void USART0_IRQHandler(void) {
#if 1
if(SET == usart_interrupt_flag_get(USART0, USART_INT_FLAG_TBE)||SET == usart_interrupt_flag_get(USART0, USART_INT_FLAG_TC)){
usart_flag_clear(USART0, USART_INT_FLAG_TBE);
usart_flag_clear(USART0, USART_INT_FLAG_TC);
p_usartSendOK = 1;
}
void DMA0_Channel3_IRQHandler(void)
{
//while(RESET == dma_interrupt_flag_get(DMA0, DMA_CH3, DMA_INTF_FTFIF));
//dma_interrupt_flag_clear(DMA0, DMA_CH3, DMA_INTF_FTFIF);
if(SET == dma_interrupt_flag_get(DMA0, DMA_CH3, DMA_INT_FLAG_FTF)){
dma_interrupt_flag_clear(DMA0, DMA_CH3, DMA_INT_FLAG_FTF);
//dma_channel_disable(DMA0, DMA_CH3);//使能DMA0_CH3
usart_flag_clear(USART0, USART_FLAG_TC);
usart_interrupt_enable(USART0, USART_INT_TC);
usart_flag_clear(USART0, USART_FLAG_TBE);
usart_interrupt_enable(USART0, USART_INT_TBE);
p_dmaSendOK = 0x01;
}
}
int main(void)
{
initGPIO();
initUART();
DMA_init();
while(1)
{
delay_ms(1000); // 延时100毫秒
TxCount=0;
//USART0 scan sla
Tx_Buf[TxCount++] = 0x0A;
Tx_Buf[TxCount++] = 0x01;
Tx_Buf[TxCount++] = 0x00;
Tx_Buf[TxCount++] = 0x21;
Tx_Buf[TxCount++] = 0x00;
Tx_Buf[TxCount++] = 0x12;
uint16_t tmpData = getModbusCRC16(Tx_Buf, TxCount);
Tx_Buf[TxCount++] = (uint8_t)(tmpData); /* crc 高字节 */
Tx_Buf[TxCount++] = (uint8_t)(tmpData>>8); /* crc 低字节 */
#if 1
tx_size = TxCount;
gpio_bit_set(GPIOA, GPIO_PIN_7);
delay_ms (1);
dma_channel_disable(DMA0, DMA_CH3);//使能DMA0_CH3
dma_flag_clear(DMA0, DMA_CH3, DMA_FLAG_FTF);//清除DMA通道传输完成标志
dma_memory_address_config(DMA0, DMA_CH3, (uint32_t)Tx_Buf);//配置存储器基地址
dma_transfer_number_config(DMA0, DMA_CH3, tx_size);
dma_channel_enable(DMA0, DMA_CH3);
usart_dma_transmit_config(USART0, USART_TRANSMIT_DMA_ENABLE); //发送
/* wait until USART0 TX DMA0 channel transfer complete */
while(!p_dmaSendOK);
p_dmaSendOK=0;
#if 1
while(!p_usartSendOK);
p_usartSendOK=0;
usart_interrupt_disable(USART0, USART_INT_TC);
#endif
gpio_bit_reset(GPIOA, GPIO_PIN_7);
delay_ms(1);
p_InputRegister = 0x0E;
#endif
}
|