最近在调试新唐 M482串口,想去判断发送数据是否发完,去读里面的寄存器读不到。- void SYS_Init(void)
- {
- /* Set XT1_OUT(PF.2) and XT1_IN(PF.3) to input mode */
- PF->MODE &= ~(GPIO_MODE_MODE2_Msk | GPIO_MODE_MODE3_Msk);
- /* Enable HXT clock (external XTAL 12MHz) */
- CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
- /* Wait for HXT clock ready */
- CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk);
- /* Set core clock as PLL_CLOCK from PLL */
- CLK_SetCoreClock(FREQ_100MHZ);
- /* Set PCLK0/PCLK1 to HCLK/2 */
- //CLK->PCLKDIV = (CLK_PCLKDIV_PCLK0DIV2 | CLK_PCLKDIV_PCLK1DIV2);
- CLK->PCLKDIV = CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2;
- CLK_EnableModuleClock(EMAC_MODULE);
- //CLK_EnableModuleClock(TMR2_MODULE);//time2_delay
- // Configure MDC clock rate to HCLK / (127 + 1) = 1.5 MHz if system is running at 192 MHz
- CLK_SetModuleClock(EMAC_MODULE, 0, CLK_CLKDIV3_EMAC(127));
- // CLK_SetModuleClock(TMR2_MODULE, CLK_CLKSEL1_TMR2SEL_HXT, 0);//time2_delay
- SYS->GPC_MFPL |= SYS_GPC_MFPL_PC6MFP_EMAC_RMII_RXD1 | SYS_GPC_MFPL_PC7MFP_EMAC_RMII_RXD0;
- SYS->GPC_MFPH |= SYS_GPC_MFPH_PC8MFP_EMAC_RMII_REFCLK;
- SYS->GPE_MFPH |= SYS_GPE_MFPH_PE8MFP_EMAC_RMII_MDC |
- SYS_GPE_MFPH_PE9MFP_EMAC_RMII_MDIO |
- SYS_GPE_MFPH_PE10MFP_EMAC_RMII_TXD0 |
- SYS_GPE_MFPH_PE11MFP_EMAC_RMII_TXD1 |
- SYS_GPE_MFPH_PE12MFP_EMAC_RMII_TXEN;
- // Enable high slew rate on all RMII TX output pins
- PE->SLEWCTL = (GPIO_SLEWCTL_HIGH << GPIO_SLEWCTL_HSREN10_Pos) |
- (GPIO_SLEWCTL_HIGH << GPIO_SLEWCTL_HSREN11_Pos) |
- (GPIO_SLEWCTL_HIGH << GPIO_SLEWCTL_HSREN12_Pos);
- }
- char uart3_send(unsigned char psdt)
- {
- printf("\n==rs485_send==
- UART_INTSTS_TXENDINT_Msk=%d,UART_INTSTS_TXENDIF_Msk=%d,UART_INTSTS_THREINT_Msk=%d,UART_INTSTS_THREIF_Msk=%d\n",UART3->INTSTS
- & UART_INTSTS_TXENDINT_Msk,UART3->INTSTS &
- UART_INTSTS_TXENDIF_Msk,UART3->INTSTS &
- UART_INTSTS_THREINT_Msk,UART3->INTSTS & UART_INTSTS_THREIF_Msk);
- printf("\n==rs485_send==
-
- UART_FIFOSTS_TXEMPTYF_Msk=%d,UART_FIFOSTS_TXFULL_Msk=%d,UART_FIFOSTS_TXEMPTY_Msk=%d\n",UART3->FIFOSTS
- & UART_FIFOSTS_TXEMPTYF_Msk,UART3->FIFOSTS &
- UART_FIFOSTS_TXFULL_Msk,UART3->FIFOSTS &
- UART_FIFOSTS_TXEMPTY_Msk);
- //if (UART_GET_INT_FLAG(UART2, UART_INTSTS_TXENDINT_Msk))//发送完成中断
- {
- UART_WRITE(UART3 , psdt);
- return (1);
- }
- //else
- //{
- // return (0);
- //}
-
- }
- void UART3_IRQHandler(void)
- {
- unsigned char rdat;
- if(UART_GET_INT_FLAG(UART3, UART_INTSTS_RDAINT_Msk) )//RDA中断
- {
- /* Get all the input characters */
- while(UART_IS_RX_READY(UART3))
- {
- /* Get the character from UART Buffer */
- rdat = UART_READ(UART3);
- rs485_serial_interrupt(rdat);
- }
- /* Disable UART RDA/THRE/Time-out interrupt */
- }
- }
- void UART3_Init(void)
- {
- /* Enable UART module clock */
- CLK_EnableModuleClock(UART3_MODULE);//允许串口1模块时钟
- /* Select UART module clock source as HXT and UART module clock divider as 1 */
- CLK_SetModuleClock(UART3_MODULE, CLK_CLKSEL3_UART3SEL_HXT, CLK_CLKDIV4_UART3(1));//设置串口1时钟为HXT
-
- /* Set GPC multi-function pins for UART1 RXD (PC9)and TXD (PC10)*/
- SYS->GPC_MFPH &= ~(SYS_GPC_MFPH_PC9MFP_Msk | SYS_GPC_MFPH_PC10MFP_Msk);
- SYS->GPC_MFPH |= (SYS_GPC_MFPH_PC9MFP_UART3_RXD | SYS_GPC_MFPH_PC10MFP_UART3_TXD);
-
- SYS_ResetModule(UART3_MODULE);//复位串口1
- /* Configure UART1 and set UART1 baud rate */
- UART_Open(UART3, 115200);
- NVIC_EnableIRQ(UART3_IRQn);
- UART_EnableInt(UART3, UART_INTEN_RDAIEN_Msk);//接收数据中断
- UART3->INTSTS = (UART_INTSTS_TXENDIF_Msk);
- //UART_EnableInt(UART1, (UART_INTEN_RDAIEN_Msk|UART_INTEN_TXENDIEN_Msk));//接收数据中断 发送完成中断
- //NVIC_SetPriority(UART1_IRQn, 0);//中断优先级
- }
- int main(void)
- {
- /* Unlock protected registers */
- SYS_UnlockReg();
- /* Init System, peripheral clock and multi-function I/O */
- SYS_Init();
- /* Lock protected registers */
- SYS_LockReg();
-
- /* Init UART0 for printf */
- UART0_Init();//串口打印
- UART3_Init();
- WDT_Init();/* Init watchdog */
-
- Kick_Dog();
- while(1)
- {
- ;
- }
- }
- 监测这如下寄存器,不管有没有数据发送下面打印出来的数据都是一样
- printf("\n==rs485_send==
- UART_INTSTS_TXENDINT_Msk=%d,UART_INTSTS_TXENDIF_Msk=%d,UART_INTSTS_THREINT_Msk=%d,UART_INTSTS_THREIF_Msk=%d\n",UART3->INTSTS
- & UART_INTSTS_TXENDINT_Msk,UART3->INTSTS &
- UART_INTSTS_TXENDIF_Msk,UART3->INTSTS &
- UART_INTSTS_THREINT_Msk,UART3->INTSTS & UART_INTSTS_THREIF_Msk);
- printf("\n==rs485_send==
-
- UART_FIFOSTS_TXEMPTYF_Msk=%d,UART_FIFOSTS_TXFULL_Msk=%d,UART_FIFOSTS_TXEMPTY_Msk=%d\n",UART3->FIFOSTS
- & UART_FIFOSTS_TXEMPTYF_Msk,UART3->FIFOSTS &
- UART_FIFOSTS_TXFULL_Msk,UART3->FIFOSTS &
- UART_FIFOSTS_TXEMPTY_Msk);
复制代码
|