Hello everyone,
I am currently working on a project that involves 2 Teensy 3.5's. They communicate using Serial1 UART over RS485.
The slave teensy is using WS2812Serial library and pin 32 (Serial4)
Now i wrote a simple communication interface to send light data from the Master to the slave. The data transfer has been tested working great. However when i try to update my light bus using the LEDBus0.show() command, i run into problems. Here is a sample below:
The Serial1Update() function is called every loop in the main loop.
Now if comment out "LEDBus0.show();" from this code, the Serial1 data transfer works just fine (but no led updates obviously). But when i uncomment this, my Serial1 bus goes crazy.
It appears as if the Serial1 and Serial4 busses are sharing memory somewhere. My guess is that the data that is supposed to go to the Serial4 Light bus, ends up being pulled in by my Serial1Update() function, throwing everything off. At least thats what it seems like is happening.
Using the OctoWS2811 library is not an option either as i need the PWM outputs for something else. Looking for a non-blocking light solution as well.
I think the TLDR question here, is do i lose the Serial1 functionality, even if i only want to use the WS2812Serial library on Pin 32 (Serial4) due to some memory sharing between the hardware serial ports?
I am currently working on a project that involves 2 Teensy 3.5's. They communicate using Serial1 UART over RS485.
The slave teensy is using WS2812Serial library and pin 32 (Serial4)
Now i wrote a simple communication interface to send light data from the Master to the slave. The data transfer has been tested working great. However when i try to update my light bus using the LEDBus0.show() command, i run into problems. Here is a sample below:
Code:
#define SLAVE_ID 1
#define LED_BUS_0_PIN 32
#define LED_BUS_0_NUM 50
byte drawingMemoryBus0[LED_BUS_0_NUM * 3]; // 3 bytes per LED
DMAMEM byte displayMemoryBus0[LED_BUS_0_NUM * 12]; // 12 bytes per LED
WS2812Serial LEDBus0(LED_BUS_0_NUM, drawingMemoryBus0, displayMemoryBus0, LED_BUS_0_PIN, WS2812_GRB);
uint8_t Serial1Instruction = 0; // Stores the current Serial instruction
uint8_t Serial1Buffer[256]; // Serial1 Buffer
uint8_t Serial1BufferIndex = 0; // Serial1 Buffer Index
void RS485Serial1Reset() {
Serial1Instruction = 0;
Serial1BufferIndex = 0;
}
void Serial1Update() {
if(Serial1.available()){
elapsedMicros Serial1Time=0; // used to keep track of time spent in the serial update
while(Serial1.available() && Serial1Time < SERIAL1_LOOP_TIMEOUT){
if (Serial1Instruction == 0){
Serial1Instruction = Serial1.read();
}
switch(Serial1Instruction){
case(0x10): // led update
if(Serial1.available() >= 203) { // 50 lights of data is 203 bytes. wait for all light data to fill buffer
Serial.println(Serial1.available());
Serial1.readBytes(Serial1Buffer, 203);
if (Serial1Buffer[0] == SLAVE_ID) {
uint8_t pixelIndex = 4;
for (uint8_t i = 0; i < Serial1Buffer[2]; i++) {
if(Serial1Buffer[1] == 0)
LEDBus0.setPixel(i, Serial1Buffer[pixelIndex], Serial1Buffer[pixelIndex + 1], Serial1Buffer[pixelIndex + 2]);
else if(Serial1Buffer[1] == 1);
//LEDBus1.setPixel(i, Serial1Buffer[pixelIndex], Serial1Buffer[pixelIndex + 1], Serial1Buffer[pixelIndex + 2]);
pixelIndex += 4;
}
if (Serial1Buffer[1] == 0)
LEDBus0.show(); // show light bus 0
else if (Serial1Buffer[1] == 1);
//LEDBus1.show(); // show light bus 1
}
RS485Serial1Reset();
}
break;
default:
RS485Serial1Reset();
break;
}
}
}
}
The Serial1Update() function is called every loop in the main loop.
Now if comment out "LEDBus0.show();" from this code, the Serial1 data transfer works just fine (but no led updates obviously). But when i uncomment this, my Serial1 bus goes crazy.
It appears as if the Serial1 and Serial4 busses are sharing memory somewhere. My guess is that the data that is supposed to go to the Serial4 Light bus, ends up being pulled in by my Serial1Update() function, throwing everything off. At least thats what it seems like is happening.
Using the OctoWS2811 library is not an option either as i need the PWM outputs for something else. Looking for a non-blocking light solution as well.
I think the TLDR question here, is do i lose the Serial1 functionality, even if i only want to use the WS2812Serial library on Pin 32 (Serial4) due to some memory sharing between the hardware serial ports?