cancel
Showing results for 
Search instead for 
Did you mean: 

SerialPort with registers

summ98
Associate

Hello, I am trying to do one simple task with my STM32 board using just registers and interruptions in USART2.

Basically I have to wait until I receive data via serialPort, then activate interruption that should increment the value of my data by 1. After this it should send via serialPort the new data incremented by 1 and wait for the next time it receives data.

Here is the code I implemented:

void serialPrint(USART_TypeDef *dir, uint8_t* data, uint32_t tam) { for (uint32_t i = 0; i < tam; i++) { dir->DR = data[i]; while (!(dir->SR & USART_SR_TC)); } } void serialScan(USART_TypeDef *dir, uint8_t* data, uint32_t tam) { for (uint32_t i = 0; i < tam; i++) { while (!(dir->SR & USART_SR_RXNE)); data[i] = dir->DR; } } void serialScanIT(USART_TypeDef *dir, uint8_t* buf, uint32_t size) { uint32_t *NVIC_ISER1 = (uint32_t*)0xE000E104U; *NVIC_ISER1 = 0x40; } void USART2_IRQHandler(void) { if (USART2->SR & USART_SR_RXNE) { dato[pos] = USART2->DR; pos++; if (pos >= size) { callback(data); deactivateIT(); } } }

 

1 REPLY 1
Pavel A.
Evangelist III

Here you can find help with reviewing your code and development of your STM32 project:

https://www.fiverr.com/categories/programming-tech/electronics-engineering/embedded-systems-iot?ref=platform%3Astm32