Page 1 of 1

STM32 USART register

Posted: Wed Nov 01, 2023 11:14 am
by Supervisor
I'm trying to use a library written for Atmel chip.

Code: Select all

commandStartNewFrame(UART_PIXEL_FORMAT_RGB565);
  for (uint16_t j=0; j<lineCount; j++) {
    for (uint16_t i=0; i<lineLength; i++) {
      waitForPreviousUartByteToBeSent();
      UDR0 = formatRgbPixelByteH(colorH);
      waitForPreviousUartByteToBeSent();
      UDR0 = formatRgbPixelByteL(colorL);
    }
  }
}
When I try to build it on platformio, it says UDR0 was not declared. I'm using STM32L432KC board. I want to port that code for STM32.

Re: STM32 USART register

Posted: Thu Nov 02, 2023 5:23 pm
by dannyf
the easiest way to port a piece of code is to understand its functionality first and then replicate that functionality on your target chip. the code here seems to be about transmitting over uart: it waits for the uart to be available, and then send something over.

so you need two functions:
1. detect if uart is available - either tx buffer not full, or uart not in transmission.
2. load up data into the transmission buffer - the uart has a data register (at a minimum), or a transmission data register (sometimes).

both are fairly easy to do.