I'm trying to read 4 bytes at 1.875Mbps every 48.6μs (so there is some time between each 4 bytes).
If I use Serial1 (UART0) it reads just fine, but when using SerialPIO it may get the first byte correct, but the rest are not. Scope shows nice square edges and bit rate.
With Serial1 I get the proper data (example) 04, B0, C0, DD.
With SerialPIO I get stuff like 04,60,81,BC (it varies slightly on everything but first byte).
Anyone else having issues with SerialPIO at high speeds?
I can paste the simplified code used for this test.
Please show us your complete formatted code and annotated schematic.
What handshaking are you using ?
I'm using a standard Arduino Pico for this test, the only connections are USB cable to computer, ground, and 3.3V TTL serial in on GPIO13.
This is SerialPIO (received bytes are wrong here)
//Serial test using SerialPIO on GPIO12 and GPIO13
uint8_t inBytes[8], inByte, inIdx;
long tmr;
SerialPIO SPIO(12,13,32);
void setup(){
Serial.begin(9600);
SPIO.begin(1875000,SERIAL_8N1);
}
void loop(){
while(SPIO.available()){
inByte = SPIO.read();
if(inIdx >7){inIdx--;} // missed start, don't exceeed array length
if(inByte < 0x08){ // start byte always 0-7
inBytes[0] = inByte;
inIdx = 1;
}else{ // data byte
inBytes[inIdx++] = inByte;
}
}
if((millis() - tmr) > 1000){
tmr = millis();
for(int i = 0; i < 8; i++){
Serial.print("\t");
Serial.print(inBytes[i],HEX);
}
Serial.println();
inBytes[4] = inBytes[5] = inBytes[6] = inBytes[7] = 0;
}
}
The code below is using UART0 with everything else being the same. (this works)
// Serial test using UART1 on GPIO12 and GPIO13
uint8_t inBytes[8], inByte, inIdx;
long tmr;
void setup(){
gpio_set_function_masked(12 | 13 , GPIO_FUNC_UART);
Serial.begin(9600);
Serial1.setRX(13);
Serial1.setTX(12);
Serial1.begin(1875000,SERIAL_8N1);
}
void loop(){
while(Serial1.available()){
inByte = Serial1.read();
if(inIdx >7){inIdx--;} // missed start, don't exceeed array length
if(inByte < 0x08){ // start byte always 0-7
inBytes[0] = inByte;
inIdx = 1;
}else{ // data byte
inBytes[inIdx++] = inByte;
}
}
if((millis() - tmr) > 1000){
tmr = millis();
for(int i = 0; i < 8; i++){
Serial.print("\t");
Serial.print(inBytes[i],HEX);
}
Serial.println();
inBytes[4] = inBytes[5] = inBytes[6] = inBytes[7] = 0;
}
}
