求助!STC8H3K64S4的P3.1端口设置和通讯问题
应国产化要求,从silicon的C8051F系列转用STC的片子。STC的片子十几年前用过,性能优异。
但是这几天,有个及其简单的GPIO设置始终没搞明白。
表现为三个问题:
//-------------------------------------
问题1:P3.0和P3.1作为下载和通讯口,P3.1是要求设置为推挽,如下:
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin=GPIO_Pin_1;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P3,&GPIO_InitStructure);
串口TX有输出。
但是如果这样设置:
P3M1 &= ~GPIO_Pin_1;P3M0 |= GPIO_Pin_1;
或者这样
P3M0 |=0x02; P3M1 &= ~0x02;
甚至这样 P3M0 |=0x02; P3M1 &= 0xFD;
串口Tx无输出。
又但是这样又有输出:
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin=GPIO_Pin_1;
P3M1 &= ~GPIO_InitStructure.Pin;P3M0 |=GPIO_InitStructure.Pin;
//-------------------------------------
问题2:其他P3口需要推挽输出
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin=GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P3,&GPIO_InitStructure);
串口Tx无输出。
//-------------------------------
问题3:P5口的P5.4推挽
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin=GPIO_Pin_1;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P3,&GPIO_InitStructure);
GPIO_InitStructure.Pin= GPIO_Pin_4;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P5,&GPIO_InitStructure);
串口Tx无输出。
但是这样:
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Pin=GPIO_Pin_1;
GPIO_InitStructure.Mode = GPIO_OUT_PP;
GPIO_Inilize(GPIO_P3,&GPIO_InitStructure);
P5M0 = 0x10; P5M1 = 0x00;
串口Tx有输出。
//有输出的情况如下:ADC0,ADC1,ADC2,ADC3,ADC6,数据正常。
1,输出一般设置成强推挽输出
2,输入一般设置成高阻输入,如是模拟量输入,建议关闭数字输入
深圳国芯人工智能有限公司-工具软件 (stcai.com)
你的问题在于串口1的波特率发生器没有设置,只要把屏蔽的这行打开就行了:
串口2固定使用定时器2作为波特率发生器,所以可以不用设置,但是其它串口都需要设置。
乘风飞扬 发表于 2023-10-11 09:44
你的问题在于串口1的波特率发生器没有设置,只要把屏蔽的这行打开就行了:
非常感谢。不好意思。
我这边把例程修改了,config里面定义了UART1(Rx=P3.0和Tx=P3.1),标题没修改。
页:
[1]