Question
STM32 HAL for Rs485 Modbus
Posted on October 28, 2014 at 11:27
Hi,
I am trying to change to HAl library from STD lib. One of the task is port modbus code. I want to receive data, however size is unknown and is time critical (2.5 chars depending on baud rate).typedef struct
{ uint8_t au8RxBuf[UART_BUF_RX_SIZE]; uint8_t au8TxBuf[UART_BUF_TX_SIZE]; uint16_t u16RxBufCnt; uint16_t u16TxBufCnt; uint8_t u8TxComplete; uint8_t u8Error; uint8_t u8RxStatus; uint8_t u8TxStatus; }uart_data_s;uart_data_s uart_data_485B;
void bsp_uart_485B_ISR(void)
{ uint8_t u8dummy; static uart_data_s *ptr; static uint16_t u16ISRTxCnt = 0; ptr = &uart_data_485B;// Receive Section
if(USART_GetITStatus(usart_conf[UART_485B].usart_peri, USART_IT_RXNE) != RESET) { bsp_GenTimer_Load(MB_PKT_SEAL_GEN_TIMERB, mbPktSealTimeout[UART_19200_BAUD]); // Maximum Timeout between bytes to seal packet u8dummy = USART_ReceiveData(usart_conf[UART_485B].usart_peri); // Read one byte from the receive data register if (UART_BUF_STATUS_FREE == (uart_buf_status_e) ptr->u8RxStatus) { if(ptr->u16RxBufCnt < UART_BUF_RX_SIZE) ptr->au8RxBuf[ptr->u16RxBufCnt++] = u8dummy; // else Neglect As buffer is not free } }// Transmit section
if(USART_GetITStatus(usart_conf[UART_485B].usart_peri, USART_IT_TXE) != RESET) { if(u16ISRTxCnt < ptr->u16TxBufCnt) USART_SendData(usart_conf[UART_485B].usart_peri, ptr->au8TxBuf[u16ISRTxCnt++]); // Send One Byte else { ptr->u8TxComplete = UART_STATUS_FREE; // Transmit Complete u16ISRTxCnt = 0; ptr->u16TxBufCnt = 0; bsp_GenTimer_Load(MB_TX_COMPLETE_TIMERB,mbPktSealTimeout[M530S_RS485B_DFLT_BAUD]); USART_ITConfig(usart_conf[UART_485A].usart_peri, USART_IT_TXE, DISABLE); // Disable Tx Interrupt } } }Note: bsp_GenTimer_Load will load timeout in software tiimers and on TImeout seal the packet or post the semaphore.
Also I am trying to check UART_Hyperterminal_IT example provided with HAL.
This example receives 10 bytes of data however if I send 15 bytes in one go code loops inside HAL_UART_IRQHandler in UART_Transmit_IT with huart->State as HAL_UART_STATE_READY. Is there any bug with this HAL lib code. Also Can you provide me the pending bug list with HAL. I have increased RxBuffer size to 32 bytes howevr receiving 10 bytes only through HAL_UART_Receive_IT. Is there any known bugs list with HAL.Regards
Chetan
