本帖最后由 forgot 于 2023-2-14 10:13 编辑
评测实现功能: 1、开机液晶显示相关信息: "Hello Geehy" "APM32F107_MINI" "USART_2_OLED"
2、可通过PC端串口发送数据到串口2,通过空闲中断判断完整帧,然后将接收到的完整帧数据显示在0.96寸的OLED液晶屏上。 "USART2_REV:xxxxx",具体内容看图片。
3、接收数据过程中LED闪烁。
开机效果:
串口接收显示效果:
外设使用情况: PE6 推挽输出点灯 PA4、PA6模拟I2C时序 USART2:接收中断与空闲中断PA2、PA3
相关图片: 整体环境搭建
开机显示:
串口发送:
串口接收显示: 主要部分代码说明: USART初始化代码: void USART_Configuration(void)
{
USART_Config_T USART_ConfigStruct;
APM_MINI_LEDInit(LED2);
RCM_EnableAPB2PeriphClock((RCM_APB2_PERIPH_T)(RCM_APB2_PERIPH_GPIOA | RCM_APB2_PERIPH_USART1));
RCM_EnableAPB1PeriphClock(RCM_APB1_PERIPH_USART2);
USART_ConfigStruct.baudRate = 115200;
USART_ConfigStruct.hardwareFlow = USART_HARDWARE_FLOW_NONE;
USART_ConfigStruct.mode = USART_MODE_TX_RX;
USART_ConfigStruct.parity = USART_PARITY_NONE;
USART_ConfigStruct.stopBits = USART_STOP_BIT_1;
USART_ConfigStruct.wordLength = USART_WORD_LEN_8B;
// APM_MINI_COMInit(COM1, &USART_ConfigStruct);
APM_MINI_COMInit(COM2, &USART_ConfigStruct);
// USART_EnableInterrupt(USART1, USART_INT_TXBE);
USART_EnableInterrupt(USART2, USART_INT_RXBNE);
USART_EnableInterrupt(USART2,USART_INT_IDLE);
// NVIC_EnableIRQRequest(USART1_IRQn, 2, 0);
NVIC_EnableIRQRequest(USART2_IRQn, 1, 0);
}
模拟I2C初始化代码: void IIC_Start()
{
OLED_SCLK_Set();
OLED_SDIN_Set();
MY_Delay(1);
OLED_SDIN_Clr();
MY_Delay(1);
OLED_SCLK_Clr();
MY_Delay(1);
}
void IIC_Stop()
{
OLED_SCLK_Set();
MY_Delay(1);
OLED_SDIN_Clr();
MY_Delay(1);
OLED_SDIN_Set();
MY_Delay(1);
}
void IIC_Wait_Ack()
{
OLED_SCLK_Set();
MY_Delay(1);
OLED_SCLK_Clr();
MY_Delay(1);
}
void Write_IIC_Byte(unsigned char IIC_Byte)
{
unsigned char i;
unsigned char m,da;
da=IIC_Byte;
OLED_SCLK_Clr();
MY_Delay(1);
for(i=0; i<8; i++) {
m=da;
m=m&0x80;
if(m==0x80) {
OLED_SDIN_Set();
} else
OLED_SDIN_Clr();
MY_Delay(1);
da=da<<1;
OLED_SCLK_Set();
MY_Delay(1);
OLED_SCLK_Clr();
MY_Delay(1);
}
}
/*************************************************/
void Write_IIC_Command(unsigned char IIC_Command)
{
IIC_Start();
Write_IIC_Byte(0x78);//Slave address,SA0=0
IIC_Wait_Ack();
Write_IIC_Byte(0x00);//write command
IIC_Wait_Ack();
Write_IIC_Byte(IIC_Command);
IIC_Wait_Ack();
IIC_Stop();
}
void Write_IIC_Data(unsigned char IIC_Data)
{
IIC_Start();
Write_IIC_Byte(0x78);//D/C#=0; R/W#=0
IIC_Wait_Ack();
Write_IIC_Byte(0x40);//write data
IIC_Wait_Ack();
Write_IIC_Byte(IIC_Data);
IIC_Wait_Ack();
IIC_Stop();
}
void OLED_WR_Byte(unsigned dat,unsigned cmd)
{
if(cmd)
Write_IIC_Data(dat);
else
Write_IIC_Command(dat);
}
液晶初始化代码: void OLED_Init(void)
{
Delay(5000);
WriteCmd(0xAE); //display off
WriteCmd(0x20); //Set Memory Addressing Mode
WriteCmd(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid
WriteCmd(0xb0); //Set Page Start Address for Page Addressing Mode,0-7
WriteCmd(0xc8); //Set COM Output Scan Direction
WriteCmd(0x00); //---set low column address
WriteCmd(0x10); //---set high column address
WriteCmd(0x40); //--set start line address
WriteCmd(0x81); //--set contrast control register
WriteCmd(0xff); //亮度调节 0x00~0xff
WriteCmd(0xa1); //--set segment re-map 0 to 127
WriteCmd(0xa6); //--set normal display
WriteCmd(0xa8); //--set multiplex ratio(1 to 64)
WriteCmd(0x3F); //
WriteCmd(0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content
WriteCmd(0xd3); //-set display offset
WriteCmd(0x00); //-not offset
WriteCmd(0xd5); //--set display clock divide ratio/oscillator frequency
WriteCmd(0xf0); //--set divide ratio
WriteCmd(0xd9); //--set pre-charge period
WriteCmd(0x22); //
WriteCmd(0xda); //--set com pins hardware configuration
WriteCmd(0x12);
WriteCmd(0xdb); //--set vcomh
WriteCmd(0x20); //0x20,0.77xVcc
WriteCmd(0x8d); //--set DC-DC enable
WriteCmd(0x14); //
WriteCmd(0xaf); //--turn on oled panel
}
串口2中断代码:void USART2_Isr(void)
{
static u16 us_rlen;
if(USART_ReadIntFlag(USART2, USART_INT_RXBNE)) {
usart2_rxBuf[us_rlen++] = (uint8_t)USART_RxData(USART2);
APM_MINI_LEDToggle(LED2);
} else if(USART_ReadIntFlag(USART2, USART_INT_IDLE)) {
if(us_rlen < 100) {
memcpy(show_buf,usart2_rxBuf,us_rlen);
show_buf[us_rlen] = '\0';
us_rlen = 0;
} else {
us_rlen = 0;
}
USART_RxData(USART2);
}
}
主程序代码: int main(void)
{
//外设初始化
USART_Configuration();
OLED_Configuration();
OLED_Init();
//全屏亮全屏灭
OLED_Fill(0xFF);
Delay(10000);
OLED_Fill(0x00);
Delay(10000);
//开机显示
OLED_ShowStr(0,0,(unsigned char*)"Hello Geehy",2);
OLED_ShowStr(0,2,(unsigned char*)"APM32F107_MINI",2);
OLED_ShowStr(0,4,(unsigned char*)"USART_2_OLED",2);
Delay(10000000);
OLED_CLS();
while (1) {
//OLED显示串口2接收的数据
OLED_ShowStr(0,0,(unsigned char*)"USART2_REV:",2);
OLED_ShowStr(0,2,(unsigned char*)show_buf,2);
Delay(100);
}
}
测试总结: 很早就用过极海的F103片子做过一些产品,之前都是用ST的标准库进行开发直接烧进去的,这是第一次用极海的库来开发测试,感觉在部分功能代码要简洁不少,具体后面再慢慢研究。 最大的遗憾就是F107的板子居然没有网口,看图片开始还以为那个银白色的电源接口是网口,本来是想着主要测试一下网络部分的,不过也没关系,好在IO都拉出来了,后面弄个模块接上去可以测试一下网络功能,毕竟这个是MINI板。 厂家的SDK和相关文档做得还是少了一点,部分外设模块的常用功能就没有写相关例程,希望后续还是能够补充起来,这样可以帮助用户提高开发效率,另外我连F107的数据手册在官网都没找到。 最后祝极海越做越好,祝国产越做越好!
|