头像-155856

a2605

个人成就

获得 5 次赞

帮助过4人

各位大佬,我想要多串口同时工作,麻烦指点一下,在线等

sys_config.c#include "sys_config.h" #include "stm32f10x.h" #include "stm32f10x_adc.h" #include "stm32f10x_bkp.h" #include "stm32f10x_can.h" #include "stm32f10x_cec.h" #include "stm32f10x_crc.h" #include "stm32f10x_dac.h" #include "stm32f10x_dbgmcu.h" #include "stm32f10x_dma.h" #include "stm32f10x_exti.h" #include "stm32f10x_flash.h" #include "stm32f10x_fsmc.h" #include "stm32f10x_gpio.h" #include "stm32f10x_i2c.h" #include "stm32f10x_iwdg.h" #include "stm32f10x_pwr.h" #include "stm32f10x_rcc.h" #include "stm32f10x_rtc.h" #include "stm32f10x_sdio.h" #include "stm32f10x_spi.h" #include "stm32f10x_tim.h" #include "stm32f10x_usart.h" #include "stm32f10x_wwdg.h" #include "misc.h" /@@*USART1配置*/ void USART1_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ENABLE ); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //USART1 TX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA &GPIO_InitStructure); //端口A; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //USART1 RX; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA &GPIO_InitStructure); //端口A; USART_InitStructure.USART_BaudRate = 115200; //波特率; USART_InitStructure.USART_WordLength = USART_WordLength_8b; //数据位8位; USART_InitStructure.USART_StopBits = USART_StopBits_1; //停止位1位; USART_InitStructure.USART_Parity = USART_Parity_No ; //无校验位; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件流控; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//收发模式; USART_Init(USART1 &USART_InitStructure);//配置串口参数; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置中断组,4位抢占优先级,4位响应优先级; NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //中断号; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应优先级; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(USART1 USART_IT_RXNE ENABLE); USART_Cmd(USART1 ENABLE); //使能串口; } void USART1_Send_Byte(u8 Data) //发送一个字节; { USART_SendData(USART1Data); while( USART_GetFlagStatus(USART1 USART_FLAG_TC) == RESET ); } void USART1_Send_String(u8 *Data) //发送字符串; { while(*Data) USART1_Send_Byte(*Data++); } void USART1_IRQHandler(void) //中断处理函数; { u8 res; if(USART_GetITStatus(USART1 USART_IT_RXNE) == SET) //判断是否发生中断; { USART_ClearFlag(USART1 USART_IT_RXNE); //清除标志位; res=USART_ReceiveData(USART1); //接收数据; USART1_Send_Byte(res); //用户自定义; } } /@@*USART2配置*/ void USART2_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ENABLE ); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART2 &USART_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(USART2 USART_IT_RXNE ENABLE); USART_Cmd(USART2 ENABLE); } void USART2_Send_Byte(u8 Data) //发送一个字节; { USART_SendData(USART2Data); while( USART_GetFlagStatus(USART2 USART_FLAG_TC) == RESET ); } void USART2_Send_String(u8 *Data) //发送字符串; { while(*Data) USART2_Send_Byte(*Data++); } void USART2_IRQHandler(void) //中断处理函数; { u8 res; if(USART_GetITStatus(USART2 USART_IT_RXNE) == SET) //判断是否发生中断; { USART_ClearFlag(USART2 USART_IT_RXNE); //清除标志位; res=USART_ReceiveData(USART2); //接收数据; USART2_Send_Byte(res); //用户自定义; } } void UART4_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC ENABLE ); RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4 ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(UART4 &USART_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(UART4 USART_IT_RXNE ENABLE); USART_Cmd(UART4 ENABLE); } void UART4_Send_Byte(u8 Data) { USART_SendData(UART4Data); while( USART_GetFlagStatus(UART4 USART_FLAG_TC) == RESET ); } void UART4_Send_String(u8 *Data) { while(*Data) UART4_Send_Byte(*Data++); } void UART4_IRQHandler(void) { u8 res; if(USART_GetITStatus(UART4 USART_IT_RXNE) == SET) { USART_ClearFlag(UART4 USART_IT_RXNE); res=USART_ReceiveData(UART4); UART4_Send_Byte(res); } } void UART5_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD ENABLE ); RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5 ENABLE ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOD &GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(UART5 &USART_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); USART_ITConfig(UART5 USART_IT_RXNE ENABLE); USART_Cmd(UART5 ENABLE); } void UART5_Send_Byte(u8 Data) { USART_SendData(UART5Data); while( USART_GetFlagStatus(UART5 USART_FLAG_TC) == RESET ); } void UART5_Send_String(u8 *Data) { while(*Data) UART5_Send_Byte(*Data++); } void UART5_IRQHandler(void) { u8 res; if(USART_GetITStatus(UART5 USART_IT_RXNE) == SET) { USART_ClearFlag(UART5 USART_IT_RXNE); res=USART_ReceiveData(UART5); UART5_Send_Byte(res); } } /@@*......GPIO配置......*/ void GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; //定义初始化结构体 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA ENABLE); GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable ENABLE);////关闭jtag功能 //SYS-LED GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA &GPIO_InitStructure); } /@@*重新定义USART1-printf配置*/ int fputc(int ch FILE *f) { USART_SendData(USART1 (uint8_t) ch); while (USART_GetFlagStatus(USART1 USART_FLAG_TC) == RESET);{} return ch; } /@@*重新定义scanf到串口,用于scanf,getchar等*/ int fgetc(FILE *f) { /@@*等待串口输入数据*/ while (USART_GetFlagStatus(USART1 USART_FLAG_RXNE) == RESET); return (int)USART_ReceiveData(USART1); } //#if 0 //void EXTI_Config(void) //{ // EXTI_InitTypeDef EXTI_InitStructure; // /@@*PD11外部中断输入*/ // EXTI_InitStructure.EXTI_Line = EXTI_Line13; // EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; // EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; // EXTI_InitStructure.EXTI_LineCmd = ENABLE; // EXTI_Init(&EXTI_InitStructure); // // /@@*PD12外部中断输入*/ // EXTI_InitStructure.EXTI_Line = EXTI_Line12; // EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; // EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; // EXTI_InitStructure.EXTI_LineCmd = ENABLE; // EXTI_Init(&EXTI_InitStructure); //} //#endif sys_config.h#ifndef __SYS_CONFIG_H_ #define __SYS_CONFIG_H_ #include "stm32f10x_conf.h" #include "stm32f10x.h" #include <stdio.h> /@@*使用位带操作,对单个IO灵活操作*/ #define GPIOA_ODR_Addr (GPIOA_base+12) //0x4001080C #define GPIOB_ODR_Addr (GPIOB_base+12) //0x40010C0C #define GPIOC_ODR_Addr (GPIOC_base+12) //0x4001100C #define GPIOD_ODR_Addr (GPIOD_base+12) //0x4001140C #define GPIOE_ODR_Addr (GPIOE_base+12) //0x4001180C #define GPIOF_ODR_Addr (GPIOF_base+12) //0x40011A0C #define GPIOG_ODR_Addr (GPIOG_base+12) //0x40011E0C #define GPIOA_IDR_Addr (GPIOA_base+8) //0x40010808 #define GPIOB_IDR_Addr (GPIOB_base+8) //0x40010C08 #define GPIOC_IDR_Addr (GPIOC_base+8) //0x40011008 #define GPIOD_IDR_Addr (GPIOD_base+8) //0x40011408 #define GPIOE_IDR_Addr (GPIOE_base+8) //0x40011808 #define GPIOF_IDR_Addr (GPIOF_base+8) //0x40011A08 #define GPIOG_IDR_Addr (GPIOG_base+8) //0x40011E08 #define PFout(n) *((volatile unsigned long *)(0x42000000+((GPIOF_ODR_Addr-0x40000000)<<5)+(n<<2))) void GPIO_Config(void); void USART1_Configuration(void); void USART2_Configuration(void); void EXTI_Config(void); void USART2_Send_Byte(u8 Data); void USART2_Send_String(u8 *Data); void USART2_IRQHandler(void); void USART1_Send_Byte(u8 Data); void USART1_Send_String(u8 *Data); #endif main.c#include <stdio.h> #include "stm32f10x.h" #include "sys_config.h" #include "sys_led.h" #include "delay.h" /@@*SYS_LED*/ int main(void) { USART1_Configuration(); USART2_Configuration(); LED_GPIO_Config(); GPIO_Config(); printf("\r\n start.......................\r\n"); while(1) { LED_ON; delay_ms(2500); printf("\r\n lock.......................\r\n"); LED_OFF; delay_ms(2500); printf("\r\n open.......................\r\n"); USART_SendData(USART1'1'); USART_SendData(USART2'A'); printf("\r\n send ok.......................\r\n"); delay_ms(2500); } } 各位大佬,我想要多串口同时工作,目前我这样配置串口,只有usart1可以正常工作收发,2/4/5都不可以,麻烦各位大佬指点一下。

Lightning OTG DIY,大家有什么想说的吗

Lightning OTG DIY ,最近想做一个线,苹果的OTG线,用来链接鼠标键盘,大家有什么好的建议可以来发言一下!

4G模块重连部分代码应该怎么写比较好呢

现在在用4G模块做一个物联网的方案,想问下各位开发有经验的朋友,4G断网重播怎么写着部分代码比较好呢,有什么好的办法或者实例代码呢?

4G通讯模块,联网

现在我在飞思卡尔上跑Liunx。用过大唐和中兴的4G模块,采用的是PPP拨号的方式,现在遇到一个小问题,就是每天都会掉线几次,掉线是很正常的,然后每次重连短的需要几秒钟,长的需要1-2分钟,所以想请教一下各位,断网的判断和断网后的处理应该怎么来写这块的代码更好一些呢?各位还有什么好的建议都可以讲一下的!

RFID天线驻波比是怎么一回事?请大牛来解释一下!

RFID天线的驻波是怎么回事呢?百度的字面说法就不要解释了!

香橙派的使用几个问题,APK,触摸

现在手里有块树莓派的开发板,orange win。我想请教大家,这块板子刷入系统以后,可以支持触摸显示屏吗?还有就是刷如安卓系统以后,可以安装APK等文件吗。可以安装类似手机类的安卓系统吗,不是电视盒子的那种!我想用来投放广告显示屏,想实现多个广告显示屏,一台服务器来控制,大家有什么好的解决方案吗。或者什么好的建议,比如用什么系统的好一点,或者用什么传输,!

超高频RFID,

我们现在做智能售卖机,板载超高频RFID,天线放于机柜的内壁,但是现在每次读取的时候,总会出现漏读的情况,RFID标签用的是H47,,我想想问下您,怎么改善现有的环境和应该如何有效的避免环境对RFID读取造成的影响!我在拆解别的RFID读写器的时候,看到别的读写器上面有放大增益模块,5w的!而我们只是用芯片来做驱动的,安装功率放大增益模块会改善吗?还有一个问题,在IOT方面有什么好的建议吗?

关于超高频RFID

关于超高频RFID有几个问题想问下,1,RFID的访问密码是厂商来设定还是自己来设定,如果为厂商设定,后期是否还可以更改密码2,RFID的EPC区,写如数据后是否可以锁定,确保其他机器只读3,怎样提高RFID的识别率4,什么会对RFID的读取造成较大的影响