2019-05-05 02:30 AM
Dear experts, can you please give a suggestion about how to proceed with the following problem?
I am trying to display the information on the PCD8544-driven LCD (aka Nokia 5110) about the incoming UART messages.
I am using STM32CubeMX to configure the peripherals and generate the initial code.
I configure UART in 'Asynchronous' Receive Only mode with baud rate 31250 bits/s to receive external messages. I also activate the global interrupt.
I would like to have an immediate response to the incoming bytes, so I put the processing code into the callback function. This ParseByte() is rather simple and takes really short time.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
ParseByte(gUartRxBuf[0]);
HAL_UART_Receive_IT(&huart2, gUartRxBuf, 1);
}
Also, the very first HAL_UART_Receive_IT(&huart2, gUartRxBuf, 1) call is there in the main() right before the infinite loop.
The number of incoming bytes is variable so it may happen that there is a bunch of several bytes right one after another. Still I prefer to receive and process them one by one.
I configure SPI in 'Transmit Only Master' mode with baud rate 4 Mbits/s to send the data to the screen.
The problem is that if I implement LCD writeout right into the HAL_UART_RxCpltCallback(), I assume, the output SPI stream gets overloaded and I don't see all the expected information on the screen.
One byte in the input UART stream takes 320 us. Tranceiving a full screen update command takes longer than that. I don't have the scope right with me at the moment, but I remember that was more than 320us. The estimation is that 84*48 pixels with baud rate 4Mbits/s would take at least 1 ms.
Thus, the first byte is received, the first LCD update starts and it is not over by the time when the second byte is received. As result the second LCD update is not started.
From what I learned, one solution is to use DMA.
As far as I understand, if I use not HAL_UART_Receive_IT() but HAL_UART_Receive_DMA(), the received data will imediately be placed into the special memory, which is supposed to eliminate some of the MCU ALU load. This is not the solution for me, right?
So, a more suitable idea would be to organize an output buffer for SPI, not the input buffer for UART. The reason is, again, that I want to react to the input messages immediately while the LCD display can be updated with some delay.
However I am really lost and I don't understand how one can initiate SPI transmit command as soon as any data appears in the buffer.
I appreciate any help!