Napisałem sobie bufor kołowy i w przerwaniu go obsługuję.
Podczas drukowania znaku czyli wywoływania funkcji
Podczas wysyłania znaku wszytko jest w porzadku program drukuje na uart komunikat i dlaej radosnie mruga diodą, niestety po odczycie danych otrzymuję poprawnie echo ale program nie wraca do pętli głównej z przerwania
Cały czas drukuje printfa na terminal podczas debuugowania po odebraniu znaku.
- // USART Interrupt Service Routine (ISR)
- void USARTx_IRQHandler(void){
- if (__HAL_USART_GET_FLAG(&UartHandle, USART_FLAG_RXNE)) {
- // the RXNE interrupt has occurred
- if (__HAL_USART_GET_IT_SOURCE(&UartHandle, USART_IT_RXNE)) {
- // the RXNE interrupt is enabled
- // TODO: read the received character and place it in the receive ring buffer
- char c;
- while(RingBuffer_PutChar(&USART_RingBuffer_Rx, c));
- // tutaj wisi program i nie wychodzi z przerwania
- // printf("USART_READ_DATA\n\r");
- }
- }
- if (__HAL_USART_GET_FLAG(&UartHandle, USART_FLAG_TXE)) {
- // the TXE interrupt has occurred
- if (__HAL_USART_GET_IT_SOURCE(&UartHandle, USART_IT_TXE)) {
- // the TXE interrupt is enabled
- // TODO: get a character from the transmit ring buffer and send it via UART
- char znak;
- if (RingBuffer_GetChar(&USART_RingBuffer_Tx, &znak)) // jesli pobrano znak poprawnie
- {
- __USART_ENABLE_IT(&UartHandle, USART_IT_TXE);
- USARTx->DR = znak; // wyslij znak
- }
- else
- {
- __USART_DISABLE_IT(&UartHandle, USART_IT_TXE); // disable interrupt // wylacz przerwanie
- }
- }
- }
- }
- bool RingBuffer_PutChar(RingBuffer *ringBuffer, char c)
- {
- assert(ringBuffer);
- if (ringBuffer) {
- if(ringBuffer->len == ringBuffer->size)
- {
- return false;
- }
- unsigned int Index = (ringBuffer->tail + ringBuffer->len) % ringBuffer->size;
- ringBuffer->buf[Index] = c;
- ringBuffer->len++;
- return true;
- }
- return false;
- }