[SOLVED] Enabling and using the UART Rx interrupt

Firmware/software/electronics/mechanics
Post Reply
roeiz
Beginner
Posts: 6
Joined: Thu Dec 06, 2018 1:22 pm

[SOLVED] Enabling and using the UART Rx interrupt

Post by roeiz » Thu May 02, 2019 8:44 am

Hi bitcraze community,

I'm trying to enable and use UART1, and more specifically, the Rx interrupt.
I have created a deck and connected a sensor I've built to the CF2 UART1 Rx pin (PC11). My sensor does transmit data over the UART as I'm seeing the expected signal using a scope.
While the CF2 UART1 initializing and testing functions do seem to work (I changed the uart1Test function to flash some LEDs), I cannot seem to use the Rx interrupt (USART_IT_RXNE).

Of course I have enabled UART1 in the config file with

Code: Select all

ENABLE_UART1
and as I wrote above, this part works.

The IRQ handler in uart1.c is as following:

Code: Select all

void __attribute__((used)) USART3_IRQHandler(void)
{
  uint8_t rxData;
  portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

  if (USART_GetITStatus(UART1_TYPE, USART_IT_RXNE))
  {
    rxData = USART_ReceiveData(UART1_TYPE) & 0x00FF;
    xQueueSendFromISR(uart1queue, &rxData, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
  }
}
and uart1Getchar function in uart1.c was changed so I can easily see if it is being executed:

Code: Select all

int uart1Getchar(char * ch)
{
  xQueueReceive(uart1queue, ch, portMAX_DELAY);          // Should be blocked on queue until USART3_IRQHandler is executed
  return 1;
}
Finally, I am creating the following task:

Code: Select all

static void spinTask()
{
	int i = 0;
	char angle[] = "000\n\r";
	systemWaitStart();
	while (1)
	{
		i = uart1Getchar(angle);        // Will be set to 1 if uart1Getchar function executes
		while (i)
		{
			ledSet(1, 0);
			vTaskDelay(M2T(100));
			ledSet(1, 1);
			vTaskDelay(M2T(100));
		}
	}
}
I am expecting to see the LEDs flashing after CF2 receives the signal over UART, however, nothing happens.
Is there anything I need to do in order to enable the use of the Rx interrupt?
I did see that the uart1Init function includes these two lines:

Code: Select all

USART_ITConfig(UART1_TYPE, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
Please advise on how should I proceed :)
Thanks
Last edited by roeiz on Mon May 06, 2019 6:27 am, edited 1 time in total.



tobias
Bitcraze
Posts: 1914
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Enabling and using the UART Rx interrupt

Post by tobias » Thu May 02, 2019 3:21 pm

What baudrate is the sensor. Maybe there is a miss-match in the baudrate?

I just updated the UART drivers with DMA transfer funcitons today and then the RX worked without problem.

roeiz
Beginner
Posts: 6
Joined: Thu Dec 06, 2018 1:22 pm

Re: Enabling and using the UART Rx interrupt

Post by roeiz » Thu May 02, 2019 4:58 pm

Both baudrates (sensor's and CF2's) are matched at 9600.

Tobias,
Is there anything needed to be done in order to enable/use the Rx?
Am I doing anything wrong?
Should I use taskToNotify or relying on the queue to block/unblock is good enough?

Would appreciate any help or lead :)

tobias
Bitcraze
Posts: 1914
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Enabling and using the UART Rx interrupt

Post by tobias » Fri May 03, 2019 6:53 am

I added two tests for uart1 and uart2. They are just echoing what ever you send in. I used a 3.3v FTDI cable connected to the uart signals. You could try it. You need to add the uart1test.c in the makefile and add "CFLAGS += -DDECK_FORCE=bcUart1Test" to you config.mk file.

roeiz
Beginner
Posts: 6
Joined: Thu Dec 06, 2018 1:22 pm

Re: [SOLVED] Enabling and using the UART Rx interrupt

Post by roeiz » Mon May 06, 2019 6:29 am

Apparently I missed a baudrate define, changing it solved the issue.

Thanks Tobias! :D

Post Reply