完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
|
|
相关推荐
19 个讨论
|
|
|
您好 HG:
我认为的一般使用串口的使用过程: 1、打开GPIO时钟 2、打开uart时钟 3、设置IO为RXD TXD 4、uart配置 包括波特率 系统时钟 停止位 数据位 校验位等等 5、使能串口 6、使用查询方式发送或者接收数据 void main() [ PRCMPeripheralRunEnable(PRCM_PERIPH_UART0);//开启串口时钟 PRCMLoadSet();//开启串口时钟 PRCMPeripheralRunEnable(PRCM_PERIPH_GPIO);//开启GPIO时钟 PRCMLoadSet();//开启GPIO时钟 IOCPinTypeUart(UART0_BASE, IOID_2 , IOID_3 , IOID_UNUSED, IOID_UNUSED);//开启GPIO时钟 //设置 uart0 波特率115200 数据长度8 1个停止位 UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(),115200,UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE); UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX7_8, UART_FIFO_RX7_8);//配置FIFO中断 UARTEnable(UART0_BASE);//使能uart0 // UARTDisable(UART0_BASE);//失能uart0 while(1) [ // 接收一个字符 // TempChar = (uint8_t)UARTCharGet(UART0_BASE); // 发送一个字符 UARTCharPut(UART0_BASE, 0x55); ] |
|
|
|
|
|
|
|
sagafa 发表于 2019-10-16 10:07 你好,还没找到呢。你能操作GPIO吗?可以的话发一个例程给我吧,我也是刚刚接触才开始学习,谢谢啦。大家一起进步!邮箱:1531095190@stu.tjpu.edu.cn |
|
|
|
|
|
|
|
brdtv 发表于 2019-10-16 10:32 您好 xiaobailong24, IO 是这么设置的,还缺少一个开启GPIO的时钟,我还没找到在哪里设置呢。 IOCPinTypeGpioOutput(IOID_6); IOCPinTypeGpioOutput(IOID_7); GPIOPinWrite(GPIO_PIN_6 | GPIO_PIN_7,0); |
|
|
|
|
|
|
|
|
您好,xiaobailong24, 给你一段完整的GPIO输出初始化和使用的程序,我尝试过的 void main(void) [ PRCMPowerDomainOn(PRCM_DOMAIN_PERIPH); while((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON)); /* Enable GPIO peripheral */ PRCMPeripheralRunEnable(PRCM_PERIPH_GPIO); PRCMLoadSet(); while(!PRCMLoadGet()); IOCPinTypeGpioOutput(IOID_6); IOCPinTypeGpioOutput(IOID_7); IOCPinTypeGpioOutput(IOID_25); IOCPinTypeGpioOutput(IOID_27); GPIOPinWrite(GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_25 | GPIO_PIN_27,1); while(1); ] |
|
|
|
|
|
|
|
|
xiaobailong24,
附上串口程序: /* Which events to trigger a UART interrupt */ #define CC26XX_UART_RX_INTERRUPT_TRIGGERS (UART_INT_RX | UART_INT_RT) /* All interrupt masks */ #define CC26XX_UART_INTERRUPT_ALL (UART_INT_OE | UART_INT_BE | UART_INT_PE | UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX | UART_INT_CTS) /*---------------------------------------------------------------------------*/ #define cc26xx_uart_isr UART0IntHandler /*---------------------------------------------------------------------------*/ static int (*input_handler)(unsigned char c); /*---------------------------------------------------------------------------*/ void InitGpio(void) [ PRCMPowerDomainOn(PRCM_DOMAIN_PERIPH); while((PRCMPowerDomainStatus(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON)); /* Enable GPIO peripheral */ PRCMPeripheralRunEnable(PRCM_PERIPH_GPIO); PRCMLoadSet(); while(!PRCMLoadGet()); IOCPinTypeGpioOutput(IOID_6); IOCPinTypeGpioOutput(IOID_7); IOCPinTypeGpioOutput(IOID_25); IOCPinTypeGpioOutput(IOID_27); GPIOPinWrite(GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_25 | GPIO_PIN_27,0); ] void UartConfig(void) [ //power_and_clock(void) /* Power on the SERIAL PD */ PRCMPowerDomainOn(PRCM_DOMAIN_SERIAL); while(PRCMPowerDomainStatus(PRCM_DOMAIN_SERIAL) != PRCM_DOMAIN_POWER_ON); /* Enable UART clock in active mode */ PRCMPeripheralRunEnable(PRCM_PERIPH_UART0); PRCMLoadSet(); while(!PRCMLoadGet()); // //accessible(void) // /* First, check the PD */ // if(PRCMPowerDomainStatus(PRCM_DOMAIN_SERIAL) // != PRCM_DOMAIN_POWER_ON) [ // return false; // ] // /* Then check the 'run mode' clock gate */ // if(!(HWREG(PRCM_BASE + PRCM_O_UARTCLKGR) & PRCM_UARTCLKGR_CLK_EN)) [ // return false; // ] // //disable_interrupts(void) // /* Acknowledge UART interrupts */ // IntDisable(INT_UART0); // /* Disable all UART module interrupts */ // UARTIntDisable(UART0_BASE, CC26XX_UART_INTERRUPT_ALL); // /* Clear all UART interrupts */ // UARTIntClear(UART0_BASE, CC26XX_UART_INTERRUPT_ALL); // // //enable_interrupts(void) // /* Clear all UART interrupts */ // UARTIntClear(UART0_BASE, CC26XX_UART_INTERRUPT_ALL); // /* Enable RX-related interrupts only if we have an input handler */ // if(input_handler) [ // /* Configure which interrupts to generate: FIFO level or after RX timeout */ // UARTIntEnable(UART0_BASE, CC26XX_UART_RX_INTERRUPT_TRIGGERS); // /* Acknowledge UART interrupts */ // IntEnable(INT_UART0); // ] //configure(void) uint32_t ctl_val = UART_CTL_UARTEN | UART_CTL_TXE; /* * Make sure the TX pin is output / high before assigning it to UART control * to avoid falling edge glitches */ IOCPinTypeGpioOutput(IOID_3); GPIOPinWrite(GPIO_PIN_3, 1); /* * Map UART signals to the correct GPIO pins and configure them as * hardware controlled. */ IOCPinTypeUart(UART0_BASE, IOID_2, IOID_3, IOID_UNUSED, IOID_UNUSED); /* Configure the UART for 115,200, 8-N-1 operation. */ UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); /* * Generate an RX interrupt at FIFO 1/2 full. * We don't really care about the TX interrupt */ UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX7_8, UART_FIFO_RX4_8); /* Enable FIFOs */ HWREG(UART0_BASE + UART_O_LCRH) |= UART_LCRH_FEN; // if(input_handler) [ // ctl_val += UART_CTL_RXE; // ] ctl_val += UART_CTL_RXE; /* Enable TX, RX (conditionally), and the UART. */ HWREG(UART0_BASE + UART_O_CTL) = ctl_val; ] */ IOCPinTypeGpioOutput(IOID_3); GPIOPinWrite(GPIO_PIN_3, 1); /* * Map UART signals to the correct GPIO pins and configure them as * hardware controlled. */ IOCPinTypeUart(UART0_BASE, IOID_2, IOID_3, IOID_UNUSED, IOID_UNUSED); /* Configure the UART for 115,200, 8-N-1 operation. */ UARTConfigSetExpClk(UART0_BASE, SysCtrlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX7_8, UART_FIFO_RX4_8); /* Enable FIFOs */ HWREG(UART0_BASE + UART_O_LCRH) |= UART_LCRH_FEN; ctl_val += UART_CTL_RXE; /* Enable TX, RX (conditionally), and the UART. */ HWREG(UART0_BASE + UART_O_CTL) = ctl_val; ] void main(void) [ uint8_t Led = 1; uint8_t TempChar; uint32_t delay; uint32_t i; //外部时钟初始化 oscillators_select_lf_xosc(); //GPIO初始化 InitGpio(); for(delay=0;delay<50000;delay++) [ for(i=0; i<100; i++); ] GPIOPinWrite(GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_25 | GPIO_PIN_27,1); UartConfig(); GPIOPinWrite(GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_25 | GPIO_PIN_27,0); while(1) [ UARTCharPut(UART0_BASE, TempChar++); // for(delay=0;delay<50000;delay++) // [ // for(i=0; i<100; i++); // ] if(Led != 0) Led = 0; else Led = 1; GPIOPinWrite(GPIO_PIN_6 | GPIO_PIN_7 | GPIO_PIN_25 | GPIO_PIN_27,Led); TempChar = (uint8_t)UARTCharGet(UART0_BASE); if(TempChar == '1') break; ] ] |
|
|
|
|
|
|
|
sagafa 发表于 2019-10-16 10:07 UART调试成功了吗?我找到了UART的例程,请参考附件3.1 Creating Example Projects Using the TI Resource Explorer |
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
545 浏览 0 评论
1609 浏览 0 评论
2045 浏览 0 评论
为啥BQ7693003DBTR芯片在和BQ769X0盒子通讯时收不到信号?
1507 浏览 0 评论
DSP 28027F 开发板 XDS100v2调试探针诊断日志显示了 Error -150 (SC_ERR_FTDI_FAIL)如何解决
1331 浏览 0 评论
AT32F407在USART2 DMA发送数据时,接包接到了要发送的数据,程序还是处于等待传输完成的标识判断中,为什么?
1756浏览 29评论
2781浏览 23评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
1723浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
1634浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
1645浏览 13评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 16:19 , Processed in 1.299530 second(s), Total 89, Slave 77 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2581