cancel
Showing results for 
Search instead for 
Did you mean: 

how to read and write data to USART_DR register without using HAL

SGupt.17
Associate

I am using this as

unsigned char USARTReadChar()

{

while(!(USART_SR_RXNE));

return USART_DR;

}

void USARTWriteChar(char data)

{

USART_DR = data;

while(!(USART_SR_TXE));

}

Build report has 4 errors, 1 warning

please suggest

Build Report:-

15:05:44 **** Build of configuration Debug for project USART test ****

make -j4 all 

arm-none-eabi-gcc -mcpu=cortex-m3 -g3 -c -I../ -x assembler-with-cpp --specs=nano.specs -mfloat-abi=soft -mthumb -o "Startup/startup_stm32f103c8tx.o" "../Startup/startup_stm32f103c8tx.s"

arm-none-eabi-gcc "../Src/main.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DSTM32F103xB -DDEBUG -c -I../Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Src/main.d" -MT"Src/main.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Src/main.o"

arm-none-eabi-gcc "../Src/stm32f1xx_hal_msp.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DSTM32F103xB -DDEBUG -c -I../Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Src/stm32f1xx_hal_msp.d" -MT"Src/stm32f1xx_hal_msp.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Src/stm32f1xx_hal_msp.o"

arm-none-eabi-gcc "../Src/stm32f1xx_it.c" -mcpu=cortex-m3 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DSTM32F103xB -DDEBUG -c -I../Inc -I../Drivers/CMSIS/Device/ST/STM32F1xx/Include -I../Drivers/CMSIS/Include -I../Drivers/STM32F1xx_HAL_Driver/Inc/Legacy -I../Drivers/STM32F1xx_HAL_Driver/Inc -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Src/stm32f1xx_it.d" -MT"Src/stm32f1xx_it.o" --specs=nano.specs -mfloat-abi=soft -mthumb -o "Src/stm32f1xx_it.o"

../Src/main.c: In function 'USARTReadChar':

../Src/main.c:209:10: error: 'USART_DR' undeclared (first use in this function); did you mean 'USART_DR_DR'?

 return USART_DR;

     ^~~~~~~~

     USART_DR_DR

../Src/main.c:209:10: note: each undeclared identifier is reported only once for each function it appears in

../Src/main.c: In function 'USARTWriteChar':

../Src/main.c:213:2: error: 'USART_DR' undeclared (first use in this function); did you mean 'USART_DR_DR'?

 USART_DR = data;

 ^~~~~~~~

 USART_DR_DR

../Src/main.c: In function 'USARTReadChar':

../Src/main.c:210:1: warning: control reaches end of non-void function [-Wreturn-type]

 }

 ^

make: *** [Src/subdir.mk:33: Src/main.o] Error 1

make: *** Waiting for unfinished jobs....

"make -j4 all" terminated with exit code 2. Build might be incomplete.

15:05:46 Build Failed. 4 errors, 1 warnings. (took 2s.406ms)

2 REPLIES 2

Figure out whatever macros you're using, and see what others are provided.

Here we just use the form

USART1->DR = data;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
unsigned char USART1ReadChar(void) {
  while(!(USART1->SR & USART_SR_RXNE));
  return USART1->DR;
}
 
void USART1WriteChar(char data)  {
  USART1->DR = data;
   while(!(USART1->SR & USART_SR_TXE));
}
 

assuming you want to use USART1.

JW