4 years, 9 months ago.

STM32 Nucleo Boards (F303K8 and L432KC) serial problems

I am having the exact same issue with both boards. Whenever I try to send a serial message to them they only seem to receive the first or first two characters.

  1. include "mbed.h"

bool ReadSerial(char * message, int messageSize);

Serial _serial(USBTX, USBRX);

int main() { _serial.baud(115200); _serial.printf("Starting\r\n"); while(1){ char message[128]; ReadSerial(message, sizeof(message)); } }

bool ReadSerial(char * message, int messageSize) { check for initialization and attempt to initialize if necessary if it still isn't initialized something must be wrong, abort call

static uint8_t serialCharIndex = 0; current index of array static char message[256]; buffer to hold incoming characters bool end = false; Pointer to the requested serial device Serial *src = &_serial;

if (src->readable()) { _serial.printf("Readable status %d\r\n", src->readable()?1:0); while(!end) { _serial.printf("Readable status %d\r\n", src->readable()?1:0); grab next character char charIn = src->getc();

wait for message start identifier ($) if (!serialCharIndex && charIn != '$') continue;

end of messgae if (charIn == '\n' || charIn == '\r') { _serial.printf("End of message\r\n"); end = true; terminate string in buffer message[serialCharIndex] = 0;

reset index serialCharIndex = 0;

send message to given dispatch function return true; } else { save char _serial.printf("Character: %c\r\n", charIn); message[serialCharIndex] = charIn;

increment to thr next index, unless we've hit the end of the array if (serialCharIndex < 255) serialCharIndex++; } } }

return false; }

Sorry the code is kind of garbage. No matter how I rewrite this it yields the same results. Any suggestions?

Be the first to answer this question.