本帖最后由 Assassin007 于 2019-3-26 19:52 编辑
最近在调udma的串口发送和接受 现在串口能发送数据了 但只能发送缓冲区的第一个字节 但是我给发送缓冲区是放了两个字节的数据 串口助手上显示只能收到第一个 数据位是8位 仲裁大小是1
下面是串口配置代码
uint8_t RxBuf[1];
uint8_t TxBuf[2]={0x0a,0x0b};
void UART_init(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0xFF;
GPIOPinConfigure(GPIO_PD7_U2TX);
GPIOPinConfigure(GPIO_PD6_U2RX);
GPIOPinTypeUART(GPIO_PORTD_BASE,GPIO_PIN_7|GPIO_PIN_6);
UARTConfigSetExpClk(UART2_BASE,SysCtlClockGet(),115200,
UART_CONFIG_WLEN_8|
UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE);
UARTFIFOLevelSet(UART2_BASE,UART_FIFO_TX1_8,UART_FIFO_RX1_8);
UARTEnable(UART2_BASE);
UARTDMAEnable(UART2_BASE,UART_DMA_TX|UART_DMA_RX);
uDMAChannelAttributeDisable(UDMA_CH0_UART2RX,
UDMA_ATTR_ALTSELECT |
UDMA_ATTR_HIGH_PRIORITY |
UDMA_ATTR_REQMASK);
uDMAChannelControlSet(UDMA_CH0_UART2RX |
UDMA_PRI_SELECT,
UDMA_SIZE_8 |
UDMA_SRC_INC_NONE |
UDMA_DST_INC_NONE |
UDMA_ARB_1);
uDMAChannelTransferSet(UDMA_CH0_UART2RX |
UDMA_PRI_SELECT,
UDMA_MODE_BASIC,
(void *)(UART2_BASE + UART_O_DR),
RxBuf,
sizeof(RxBuf));
uDMAChannelAttributeDisable(UDMA_CH1_UART2TX,
UDMA_ATTR_ALTSELECT|
UDMA_ATTR_HIGH_PRIORITY|
UDMA_ATTR_REQMASK);
uDMAChannelControlSet(UDMA_CH1_UART2TX |
UDMA_PRI_SELECT,
UDMA_SIZE_8 |
UDMA_SRC_INC_NONE |
UDMA_DST_INC_NONE |
UDMA_ARB_4);
uDMAChannelTransferSet(UDMA_CH1_UART2TX |
UDMA_PRI_SELECT,
UDMA_MODE_BASIC,
TxBuf,
(void *)(UART2_BASE + UART_O_DR),
sizeof(TxBuf));
uDMAChannelEnable(UDMA_CH0_UART2RX);
uDMAChannelEnable(UDMA_CH1_UART2TX);
UARTIntEnable(UART2_BASE, UART_INT_DMARX);
UARTIntEnable(UART2_BASE, UART_INT_DMATX);
IntEnable(INT_UART2);
}
void UART2_DMA_TX(uint8_t *p)
{
uDMAChannelTransferSet(UDMA_CH1_UART2TX | UDMA_PRI_SELECT,
UDMA_MODE_BASIC,p,
(void *)(UART2_BASE + UART_O_DR),
sizeof(p));
uDMAChannelEnable(UDMA_CH1_UART2TX);
uDMAChannelRequest(UDMA_CH1_UART2TX);
}
void UART2_DMA_RX(uint8_t *p)
{
uDMAChannelTransferSet(UDMA_CH0_UART2RX | UDMA_PRI_SELECT,
UDMA_MODE_BASIC,
(void *)(UART2_BASE + UART_O_DR),
p,
sizeof(p));
uDMAChannelEnable(UDMA_CH0_UART2RX);
// uDMAChannelRequest(UDMA_CH0_UART2RX);
}
void UART2IntHandler(void)
{
uint32_t ui32Status;
uint32_t ui32Mode;
ui32Status = UARTIntStatus(UART2_BASE, 1);
UARTIntClear(UART2_BASE, ui32Status);
ui32Mode = uDMAChannelModeGet(UDMA_CH1_UART2TX | UDMA_PRI_SELECT);
if(ui32Mode == UDMA_MODE_STOP)
{
uDMAChannelTransferSet(UDMA_CH1_UART2TX | UDMA_PRI_SELECT,
UDMA_MODE_BASIC, TxBuf,
(void *)(UART2_BASE + UART_O_DR),
sizeof(TxBuf));
uDMAChannelEnable(UDMA_CH1_UART2TX);
}
if(!uDMAChannelIsEnabled(UDMA_CH0_UART2RX))
{
uDMAChannelTransferSet(UDMA_CH0_UART2RX | UDMA_PRI_SELECT,
UDMA_MODE_BASIC,
(void *)(UART2_BASE + UART_O_DR),RxBuf,
sizeof(RxBuf));
uDMAChannelEnable(UDMA_CH0_UART2RX);
}
} |