用stm32f103vb的片子驱动9325.刚接触这个。按照原子的步骤,先确定能读到ID后,在往下走,可是就是读不到,不知为何,我把代码贴出来,请大家指导,谢谢
void WriteData16(u16 data)
{
u8 temp1,temp2;
rs = 1;//写数据???这是LCD中的规矩
cs = 0;
temp1 = data>>8;
GPIOE->ODR = temp1; //写高八位
wr = 0;
wr = 1; //上升沿写入数据
temp2 = (u8)data;
GPIOE->ODR = temp2; //写低八位
wr = 0;
wr = 1;
cs = 1;
}
void WriteReg(u8 data)
{
rs = 0;//写地址,就相当是命令了
cs = 0;
GPIOE->ODR = data;
wr = 0;
wr = 1;
cs = 1;
}
void WriteRegVal(u8 addr,u16 data)
{
WriteReg(addr);
WriteData16(data);
}
/***
#define rs PDout(0)
#define wr PDout(1)
#define cs PDout(2)
#define rd PDout(4)
#define rst PDout(3)
****/
u16 ReadReg(u8 addr)
{
u16 temp;
WriteReg(addr);
GPIOE->CRL = 0x88888888; //上拉输入
GPIOE->ODR = 0xff;
rs = 1;
cs = 0;
wr = 0;
wr = 1;
temp = GPIOE->IDR;
temp <<= 8;
wr = 0;
wr = 1;
temp += GPIOE->IDR;
cs = 1;
GPIOE->CRL = 0x33333333; //上拉输出
GPIOE->ODR = 0xff;
return temp;
}
void TftInit(void)
{
u16 ID = 0;
RCC->APB2ENR |= 1 << 6;//打开PE的时钟
GPIOE->CRL &= 0x00000000;
GPIOE->CRL |= 0x33333333;//数据接口,推挽输出
GPIOE->ODR = 0xff;
RCC->APB2ENR |= 1 << 5;//打开PD时钟
GPIOD->CRL &= 0xfff00000;
GPIOD->CRL |= 0x00033333;
GPIOD->ODR = 0x17;
delay_ms(50);
WriteRegVal(0x00,0x0001);
delay_ms(50);
ID = ReadReg(0x00);
if(ID == 0x9325)
{
led1 = 0;
}
printf("ID is :%d\n",ID);
}
|