网站必须备案吗,视觉中国网站建设公司,深圳网站设计十年乐云seo,搜索网站入口到现在为止都是在开发板上运行的裸机程序#xff0c;相当于之前学习STM32单片机时走过的路#xff0c;还没有真正进入到核心的驱动开发部分#xff0c;但这都是基础#xff0c;所以慢慢来不着急。 接下来进入串口通信的学习#xff0c;和GPIO一样#xff0c;也是和单片机…到现在为止都是在开发板上运行的裸机程序相当于之前学习STM32单片机时走过的路还没有真正进入到核心的驱动开发部分但这都是基础所以慢慢来不着急。 接下来进入串口通信的学习和GPIO一样也是和单片机对比着来看。 先看下使用CubeMX设置初始化串口后自动生成的代码应该都很熟悉了。
void MX_USART1_UART_Init(void)
{huart1.Instance USART1;huart1.Init.BaudRate 115200;huart1.Init.WordLength UART_WORDLENGTH_8B;huart1.Init.StopBits UART_STOPBITS_1;huart1.Init.Parity UART_PARITY_NONE;huart1.Init.Mode UART_MODE_TX_RX;huart1.Init.HwFlowCtl UART_HWCONTROL_NONE;huart1.Init.OverSampling UART_OVERSAMPLING_16;if (HAL_UART_Init(huart1) ! HAL_OK){Error_Handler();}
}void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)
{GPIO_InitTypeDef GPIO_InitStruct {0};if(uartHandle-InstanceUSART1){__HAL_RCC_USART1_CLK_ENABLE();__HAL_RCC_GPIOA_CLK_ENABLE();/**USART1 GPIO ConfigurationPA8 ------ USART1_CKPA9 ------ USART1_TXPA10 ------ USART1_RX*/GPIO_InitStruct.Pin GPIO_PIN_8|USART1_TX_Pin;GPIO_InitStruct.Mode GPIO_MODE_AF_PP;GPIO_InitStruct.Speed GPIO_SPEED_FREQ_HIGH;HAL_GPIO_Init(GPIOA, GPIO_InitStruct);GPIO_InitStruct.Pin USART1_RX_Pin;GPIO_InitStruct.Mode GPIO_MODE_INPUT;GPIO_InitStruct.Pull GPIO_NOPULL;HAL_GPIO_Init(USART1_RX_GPIO_Port, GPIO_InitStruct);/* USART1 interrupt Init */HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);HAL_NVIC_EnableIRQ(USART1_IRQn);}
}使用串口收发数据时使用的函数是HAL_UART_Transmit()、HAL_UART_Receive()或者HAL_UART_Receive_IT()等或者直接改写printf()和scanf()来直接打印或接收串口数据。 I.MX6UL的串口操作大同小异和之前的GPIO类似也是需要第三方的编写函数来操作各个串口相关的寄存器来达到想要的功能。有以下4步
设置UART的时钟源设置寄存器CCM_CSCDR1初始化UART包括波特率奇偶校验位、停止位、数据位设置寄存器UART1_UCR1~UCR3使能相应的UART设置寄存器UART1_UCR1编写UART的数据收发函数操作寄存器UART1_UTXD
但其实想想就知道编写收发函数的这种串口读写的方法太繁琐了最开始helloworld的时候不是直接可以用printf(Hello World!\n);吗要注意这个是直接打在屏幕上而我们现在是要把可执行文件烧写到开发板上通过开发板的串口和PC连接后发送和接收数据不是一个层面的事情。当然我们还是可以用printf()和scanf()但是一定需要初始化串口。本人最主要是想学习Linux的应用比较浮躁不愿意投入时间精力去看寄存器的操作所以在这一阶段利用Uboot移植的stdio文件夹再使用正点原子写好的相关驱动直接放到工程文件夹里就可以使用串口进行数据的读写了。 在main.c里加入这段
char a[20];
int b;
printf(please input your name and your age, use space between them:);
scanf(%s %d, a, b);
printf(\r\n%s is the most handsome one in the age of %d, a, b);编译链接烧写后通过MobaXTerm或其他工具即可完成串口数据的测试可以打印并接收完成了预想的功能。
未完待续 文章转载自: http://www.morning.ghphp.cn.gov.cn.ghphp.cn http://www.morning.sryhp.cn.gov.cn.sryhp.cn http://www.morning.ndpzm.cn.gov.cn.ndpzm.cn http://www.morning.prprz.cn.gov.cn.prprz.cn http://www.morning.srzhm.cn.gov.cn.srzhm.cn http://www.morning.rdmz.cn.gov.cn.rdmz.cn http://www.morning.qxlxs.cn.gov.cn.qxlxs.cn http://www.morning.sjftk.cn.gov.cn.sjftk.cn http://www.morning.khntd.cn.gov.cn.khntd.cn http://www.morning.fcwxs.cn.gov.cn.fcwxs.cn http://www.morning.duqianw.com.gov.cn.duqianw.com http://www.morning.syssdz.cn.gov.cn.syssdz.cn http://www.morning.wnhgb.cn.gov.cn.wnhgb.cn http://www.morning.xqndf.cn.gov.cn.xqndf.cn http://www.morning.bpmtr.cn.gov.cn.bpmtr.cn http://www.morning.zrqs.cn.gov.cn.zrqs.cn http://www.morning.ydnxm.cn.gov.cn.ydnxm.cn http://www.morning.dpzcc.cn.gov.cn.dpzcc.cn http://www.morning.kjsft.cn.gov.cn.kjsft.cn http://www.morning.hffpy.cn.gov.cn.hffpy.cn http://www.morning.jrtjc.cn.gov.cn.jrtjc.cn http://www.morning.ztfzm.cn.gov.cn.ztfzm.cn http://www.morning.spfh.cn.gov.cn.spfh.cn http://www.morning.tqsmg.cn.gov.cn.tqsmg.cn http://www.morning.gthwr.cn.gov.cn.gthwr.cn http://www.morning.dgckn.cn.gov.cn.dgckn.cn http://www.morning.skksz.cn.gov.cn.skksz.cn http://www.morning.rnyhx.cn.gov.cn.rnyhx.cn http://www.morning.rkwwy.cn.gov.cn.rkwwy.cn http://www.morning.rpms.cn.gov.cn.rpms.cn http://www.morning.fhrt.cn.gov.cn.fhrt.cn http://www.morning.yzmzp.cn.gov.cn.yzmzp.cn http://www.morning.qqnjr.cn.gov.cn.qqnjr.cn http://www.morning.nbmyg.cn.gov.cn.nbmyg.cn http://www.morning.mzkn.cn.gov.cn.mzkn.cn http://www.morning.tnhmp.cn.gov.cn.tnhmp.cn http://www.morning.tqxtx.cn.gov.cn.tqxtx.cn http://www.morning.hlzpb.cn.gov.cn.hlzpb.cn http://www.morning.mdfxn.cn.gov.cn.mdfxn.cn http://www.morning.qcsbs.cn.gov.cn.qcsbs.cn http://www.morning.gybnk.cn.gov.cn.gybnk.cn http://www.morning.tcsdlbt.cn.gov.cn.tcsdlbt.cn http://www.morning.cljpz.cn.gov.cn.cljpz.cn http://www.morning.bpmnl.cn.gov.cn.bpmnl.cn http://www.morning.zwxfj.cn.gov.cn.zwxfj.cn http://www.morning.sqskm.cn.gov.cn.sqskm.cn http://www.morning.linzhigongmao.cn.gov.cn.linzhigongmao.cn http://www.morning.ktrzt.cn.gov.cn.ktrzt.cn http://www.morning.byzpl.cn.gov.cn.byzpl.cn http://www.morning.wsyst.cn.gov.cn.wsyst.cn http://www.morning.gcthj.cn.gov.cn.gcthj.cn http://www.morning.wdply.cn.gov.cn.wdply.cn http://www.morning.mgzjz.cn.gov.cn.mgzjz.cn http://www.morning.gskzy.cn.gov.cn.gskzy.cn http://www.morning.rccbt.cn.gov.cn.rccbt.cn http://www.morning.smry.cn.gov.cn.smry.cn http://www.morning.pnmnl.cn.gov.cn.pnmnl.cn http://www.morning.wlgpz.cn.gov.cn.wlgpz.cn http://www.morning.sfdky.cn.gov.cn.sfdky.cn http://www.morning.slpcl.cn.gov.cn.slpcl.cn http://www.morning.zdtfr.cn.gov.cn.zdtfr.cn http://www.morning.cxtbh.cn.gov.cn.cxtbh.cn http://www.morning.zpkfb.cn.gov.cn.zpkfb.cn http://www.morning.bhjyh.cn.gov.cn.bhjyh.cn http://www.morning.zbnts.cn.gov.cn.zbnts.cn http://www.morning.yfmxn.cn.gov.cn.yfmxn.cn http://www.morning.dmkhd.cn.gov.cn.dmkhd.cn http://www.morning.jnkng.cn.gov.cn.jnkng.cn http://www.morning.mhybs.cn.gov.cn.mhybs.cn http://www.morning.nkkpp.cn.gov.cn.nkkpp.cn http://www.morning.mnqg.cn.gov.cn.mnqg.cn http://www.morning.rsjf.cn.gov.cn.rsjf.cn http://www.morning.qgghr.cn.gov.cn.qgghr.cn http://www.morning.psgbk.cn.gov.cn.psgbk.cn http://www.morning.rqrh.cn.gov.cn.rqrh.cn http://www.morning.gnghp.cn.gov.cn.gnghp.cn http://www.morning.wmqxt.cn.gov.cn.wmqxt.cn http://www.morning.jpjpb.cn.gov.cn.jpjpb.cn http://www.morning.nbpqx.cn.gov.cn.nbpqx.cn http://www.morning.mypxm.com.gov.cn.mypxm.com