Giter Site home page Giter Site logo

particlesoftserial's People

Contributors

scruffr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

particlesoftserial's Issues

Missing serial defines

I was unable to simply include this library in to a Particle project because #include <ParticleSoftSerial.h> in ParticleSoftSerial.cpp wasn't able to find the source. I manually brought in these two files and the IDE was not able to find a number of defines.

src/ParticleSoftSerial.cpp:126:16: error: 'SERIAL_DATA_BITS_9' was not declared in this scope
   if (config & SERIAL_DATA_BITS_9)
                ^
src/ParticleSoftSerial.cpp:130:21: error: 'SERIAL_DATA_BITS_7' was not declared in this scope
   else if (config & SERIAL_DATA_BITS_7)
                     ^
src/ParticleSoftSerial.cpp:139:16: error: 'SERIAL_STOP_BITS_2' was not declared in this scope
   if (config & SERIAL_STOP_BITS_2)
                ^
src/ParticleSoftSerial.cpp:148:16: error: 'SERIAL_PARITY' was not declared in this scope
   if (config & SERIAL_PARITY)
                ^
src/ParticleSoftSerial.cpp:150:25: error: 'SERIAL_PARITY_ODD' was not declared in this scope
     _parity = (config & SERIAL_PARITY_ODD) ? 0x11 : 0x10;
                         ^

I'm pretty new to all this and C so I'm not certain if this was the right thing to do, but I was able to fix the errors above by adding the missing defines from https://github.com/gruvin/core-firmware/blob/master/hal/inc/usart_hal.h in to ParticleSoftSerial.h:

#if PLATFORM_ID == 10 // Electron
	#define TOTAL_USARTS		5
#else
	#define TOTAL_USARTS		2
#endif
#define SERIAL_BUFFER_SIZE      64

// Pre-defined USART configurations
#define SERIAL_7E1 (uint32_t)(SERIAL_DATA_BITS_7 | SERIAL_PARITY_EVEN | SERIAL_STOP_BITS_1)
#define SERIAL_7E2 (uint32_t)(SERIAL_DATA_BITS_7 | SERIAL_PARITY_EVEN | SERIAL_STOP_BITS_2)
#define SERIAL_7O1 (uint32_t)(SERIAL_DATA_BITS_7 | SERIAL_PARITY_ODD  | SERIAL_STOP_BITS_1)
#define SERIAL_7O2 (uint32_t)(SERIAL_DATA_BITS_7 | SERIAL_PARITY_ODD  | SERIAL_STOP_BITS_2)
#define SERIAL_8N1 (uint32_t)(SERIAL_DATA_BITS_8 | SERIAL_PARITY_NO   | SERIAL_STOP_BITS_1)
#define SERIAL_8N2 (uint32_t)(SERIAL_DATA_BITS_8 | SERIAL_PARITY_NO   | SERIAL_STOP_BITS_2)
#define SERIAL_8E1 (uint32_t)(SERIAL_DATA_BITS_8 | SERIAL_PARITY_EVEN | SERIAL_STOP_BITS_1)
#define SERIAL_8E2 (uint32_t)(SERIAL_DATA_BITS_8 | SERIAL_PARITY_EVEN | SERIAL_STOP_BITS_2)
#define SERIAL_8O1 (uint32_t)(SERIAL_DATA_BITS_8 | SERIAL_PARITY_ODD  | SERIAL_STOP_BITS_1)
#define SERIAL_8O2 (uint32_t)(SERIAL_DATA_BITS_8 | SERIAL_PARITY_ODD  | SERIAL_STOP_BITS_2)
#define SERIAL_9N1 (uint32_t)(SERIAL_DATA_BITS_9 | SERIAL_PARITY_NO   | SERIAL_STOP_BITS_1)
#define SERIAL_9N2 (uint32_t)(SERIAL_DATA_BITS_9 | SERIAL_PARITY_NO   | SERIAL_STOP_BITS_2)

// Serial Configuration masks
#define SERIAL_STOP_BITS      ((uint32_t)0b00000011)
#define SERIAL_PARITY         ((uint32_t)0b00001100)
#define SERIAL_DATA_BITS      ((uint32_t)0b00110000)
#define SERIAL_FLOW_CONTROL   ((uint32_t)0b11000000)

// Stop bits
#define SERIAL_STOP_BITS_1    ((uint32_t)0b00000000)
#define SERIAL_STOP_BITS_2    ((uint32_t)0b00000001)
#define SERIAL_STOP_BITS_0_5  ((uint32_t)0b00000010)
#define SERIAL_STOP_BITS_1_5  ((uint32_t)0b00000011)

// Parity
#define SERIAL_PARITY_NO      ((uint32_t)0b00000000)
#define SERIAL_PARITY_EVEN    ((uint32_t)0b00000100)
#define SERIAL_PARITY_ODD     ((uint32_t)0b00001000)

// Data bits
#define SERIAL_DATA_BITS_8    ((uint32_t)0b00000000)
#define SERIAL_DATA_BITS_9    ((uint32_t)0b00010000)
#define SERIAL_DATA_BITS_7    ((uint32_t)0b00100000)

// Flow control settings
#define SERIAL_FLOW_CONTROL_NONE    ((uint32_t)0b00000000)
#define SERIAL_FLOW_CONTROL_RTS     ((uint32_t)0b01000000)
#define SERIAL_FLOW_CONTROL_CTS     ((uint32_t)0b10000000)
#define SERIAL_FLOW_CONTROL_RTS_CTS ((uint32_t)0b11000000)

// LIN Configuration masks
#define LIN_MODE        ((uint32_t)0x0300)
#define LIN_BREAK_BITS  ((uint32_t)0x0C00)

// LIN modes
#define LIN_MODE_MASTER ((uint32_t)0x0100)
#define LIN_MODE_SLAVE  ((uint32_t)0x0200)

// LIN break settings
// Supported only in Master mode
#define LIN_BREAK_13B   ((uint32_t)0x0000)
// Supported only in Slave mode
#define LIN_BREAK_10B   ((uint32_t)0x0800)
#define LIN_BREAK_11B   ((uint32_t)0x0C00)

// Pre-defined LIN configurations
#define LIN_MASTER_13B (uint32_t)(((uint32_t)SERIAL_8N1) | LIN_MODE_MASTER | LIN_BREAK_13B)
#define LIN_SLAVE_10B  (uint32_t)(((uint32_t)SERIAL_8N1) | LIN_MODE_SLAVE  | LIN_BREAK_10B)
#define LIN_SLAVE_11B  (uint32_t)(((uint32_t)SERIAL_8N1) | LIN_MODE_SLAVE  | LIN_BREAK_11B)

Guessing there are more issues in my future? Is there a better solution or?

System.sleep(pin,...) does not work when using ParticleSoftSerial

On the Particle Photon, the function System.sleep(pin, RISING, 60); does not reliable sleep when the ParticleSoftSerial is being used.

In this code the the call to System.sleep usually will abort the sleep nearly immediately.

#include <Particle.h>
SYSTEM_MODE(MANUAL);
SYSTEM_THREAD(ENABLED);
#include <ParticleSoftSerial.h>

uint32_t lastSleep;
#define SLEEP_PIN D1

ParticleSoftSerial ss(D4,D5);

void setup()
{
  WiFi.off();
  Serial.begin();
  ss.begin(9600); // Comment out this line and sleep/wakeup works
  pinMode(SLEEP_PIN,INPUT_PULLDOWN);
  lastSleep = millis();
}

void loop()
{
  if (millis()-lastSleep > 10000) {
    Serial.println("Going to sleep");
    delay(1000);
    System.sleep(SLEEP_PIN,RISING,10);
    delay(1000);
    Serial.println("Waking up");
    lastSleep = millis();
  }
}

Adding these lines

    ss.end();
    System.sleep(SLEEP_PIN,RISING,10);
    ss.begin(9600);

causes the sleep to behave as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.