UART1 with DMA
Posted: Fri Nov 20, 2015 4:45 pm
Hi,
I'm using UART1 and DMA with uart.c and uart.h ChibiOS libraries.
I have a problem: the function rxend is executed only at the first reception of a frame.
I tried to enable the circular dma mode for rx but it didn't work.
Why? Could someone help me?
In attached there is an abstract of my code.
Thanks for the help,
Veronica
static const uint8_t message[] = "0123456789ABCD\r\n";
static uint8_t buffer[1], appoggio[5];
/*
* This callback is invoked when a receive buffer has been completely written.
*/
static void rxend(UARTDriver *uartp)
{
(void)uartp;
static unsigned char i = 0;
/* When the buffer is full, flush it and restart listening */
appoggio[i]= buffer[0];
i++;
if (i >= 5)
i=0;
uartStopReceive(&UARTD1);
uartStartReceive(&UARTD1, 1, buffer);
}
/*
* UART driver configuration structure.
*/
static UARTConfig uartcfg = {
txend1, /* End of transmission callback */
txend2, /* Physical end of transmission callback */
rxend, /* Receive buffer filled callback */
rxchar, /*UART1RXInterrupt,rxchar, Character received while out */
rxerr, /* Receive error callback */
19200,
USART_CR1_8BIT_WORD | USART_CR1_UE | USART_CR1_TE | USART_CR1_RE, //8bit and no parity check, TX e RX enable
0,
0
};
int main(void)
{
halInit();
chSysInit();
/*Init UART1*/
uartStart(&UARTD1, &uartcfg);
uartStopReceive(&UARTD1);
uartStopSend(&UARTD1);
uartStartSend(&UARTD1, 16, message);
uartStartReceive(&UARTD1, 1, buffer);
chThdSleepMilliseconds(1000);
while (TRUE)
{
//PortC = palReadPort(GPIOC);
SwitchState = palReadPad(GPIOC, GPIOC_SWITCH);
}
}
I'm using UART1 and DMA with uart.c and uart.h ChibiOS libraries.
I have a problem: the function rxend is executed only at the first reception of a frame.
I tried to enable the circular dma mode for rx but it didn't work.
Why? Could someone help me?
In attached there is an abstract of my code.
Thanks for the help,
Veronica
static const uint8_t message[] = "0123456789ABCD\r\n";
static uint8_t buffer[1], appoggio[5];
/*
* This callback is invoked when a receive buffer has been completely written.
*/
static void rxend(UARTDriver *uartp)
{
(void)uartp;
static unsigned char i = 0;
/* When the buffer is full, flush it and restart listening */
appoggio[i]= buffer[0];
i++;
if (i >= 5)
i=0;
uartStopReceive(&UARTD1);
uartStartReceive(&UARTD1, 1, buffer);
}
/*
* UART driver configuration structure.
*/
static UARTConfig uartcfg = {
txend1, /* End of transmission callback */
txend2, /* Physical end of transmission callback */
rxend, /* Receive buffer filled callback */
rxchar, /*UART1RXInterrupt,rxchar, Character received while out */
rxerr, /* Receive error callback */
19200,
USART_CR1_8BIT_WORD | USART_CR1_UE | USART_CR1_TE | USART_CR1_RE, //8bit and no parity check, TX e RX enable
0,
0
};
int main(void)
{
halInit();
chSysInit();
/*Init UART1*/
uartStart(&UARTD1, &uartcfg);
uartStopReceive(&UARTD1);
uartStopSend(&UARTD1);
uartStartSend(&UARTD1, 16, message);
uartStartReceive(&UARTD1, 1, buffer);
chThdSleepMilliseconds(1000);
while (TRUE)
{
//PortC = palReadPort(GPIOC);
SwitchState = palReadPad(GPIOC, GPIOC_SWITCH);
}
}