2016-10-23 04:00 PM
Hi.
I'd like to use the UART for MIDI input. I've configured the UART on my STM32F7-Discovery board and perform a led toggle whenever an incoming message is received. I'm using the interrupt mode similar to the Cube firmware example ''UART_TwoBoards_ComIT''. However my receive buffer is unchanged and I've initialized it with dummy-data just to confirm that it doesn't seem to get updated by the USART6_IrqHandler routine. What I get is a ''frame error'' in the UART_ErrorCallback routine. Could this have anything to do with the fact that a MIDI-note down consists of 3 bytes? When I hit a note on the MIDI-keyboard the IRQ-handler is only triggered once! This is unlike how I've worked with UART on other platforms. Then the incoming callback is triggered three times on a MIDI note-on event since it consists of 3 bytes.void
USART6_IRQHandler(
void
)
{
extern
uint8_t aRxBuffer[];
BSP_LED_Toggle(LED1);
BSP_LCD_DisplayIntAt(0, 70, *(UartHandle.pRxBuffPtr), CENTER_MODE);
HAL_UART_IRQHandler(&UartHandle);
}
void
my_UART_Init(UART_HandleTypeDef *UartHandle)
{
UartHandle->Instance = USART6;
UartHandle->Init.BaudRate = 31250;
UartHandle->Init.WordLength = UART_WORDLENGTH_8B;
UartHandle->Init.StopBits = UART_STOPBITS_1;
UartHandle->Init.Parity = UART_PARITY_NONE;
UartHandle->Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle->Init.Mode = UART_MODE_TX_RX;
UartHandle->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if
(HAL_UART_DeInit(UartHandle) != HAL_OK)
{
Error_Handler();
}
if
(HAL_UART_Init(UartHandle) != HAL_OK)
{
Error_Handler();
}
}
#stm32f746g-discovery-uart-midi
2016-10-23 05:17 PM
I would suggest prioritizing the call back into the HAL handler, and not trying to paint to the LCD
2016-10-24 02:52 AM
That also crossed my mind. I've tried to run it with only the HAL_UART_IRQHandler(&UartHandle) but still this ''frame error''. The frame error problem seems to be caused by something else obviously.
Edit: I thought I could just take the hardware part for MIDI-in (4N35 optocoupler) since it worked well under a Teensy environment but that is a 5V environment however. I have found out that my setup suffers from noise problems. However the ''noise'' error code rarely showed up. Shortening the lead between the Rx input and optocoupler output allows me to get all three interrupt callbacks with no error callback at all. However nothing is still written to the receive buffer. The libraries I have access to don't have a USART_ReceiveData function implemented.