我想通过 写读 FifoData来验证rc531 操作是否成功
cpu用的是stm32 ,A0 A1 A2 是高 高 低 并口模式
那写寄存器时应该是 [写reg -> 写数据] 读寄存器是 [写reg -> 读数据] 是这样吗?
mcu接口的屏 一般写寄存器 AlE 信号是低 写Data ALE 信号是高
看上面的时序图,好像正好是反的,我按照lcd屏的时序去读写 也不行
哪位有现成的代码可以参考下吗
下面是我的代码
#define RF_CS GPIO_Pin_9 //GPIOD
#define RF_RESET GPIO_Pin_6 //GPIOD
#define RF_ALE GPIO_Pin_10 //GPIOD
#define RF_WR GPIO_Pin_7 //GPIOD
#define RF_RD GPIO_Pin_8 //GPIOD
#define RF_CS_HIGH GPIO_SetBits(GPIOD,RF_CS)
#define RF_CS_LOW GPIO_ResetBits(GPIOD,RF_CS)
#define RF_RESET_HIGH GPIO_SetBits(GPIOD,RF_RESET)
#define RF_RESET_LOW GPIO_ResetBits(GPIOD,RF_RESET)
#define RF_ALE_HIGH GPIO_SetBits(GPIOD,RF_ALE)
#define RF_ALE_LOW GPIO_ResetBits(GPIOD,RF_ALE)
#define RF_WR_HIGH GPIO_SetBits(GPIOD,RF_WR)
#define RF_WR_LOW GPIO_ResetBits(GPIOD,RF_WR)
#define RF_RD_HIGH GPIO_SetBits(GPIOD,RF_RD)
#define RF_RD_LOW GPIO_ResetBits(GPIOD,RF_RD)
void rf_gpio_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD,ENABLE);
/* 并口 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
RF_CS_HIGH;
RF_RD_HIGH;
RF_ALE_LOW;
}
void rf_write_cmd(u8 cmd)
{
RF_RD_HIGH;
RF_WR_HIGH;
RF_CS_HIGH;
GPIOC->CRL = 0x22222222;
GPIOC->ODR = (u16)cmd;
RF_ALE_HIGH;
Delay(0x1f);
RF_ALE_LOW;
RF_RD_HIGH;
RF_WR_HIGH;
RF_CS_HIGH;
}
void rf_write_data(u8 data)
{
RF_ALE_LOW;
RF_WR_LOW;
RF_RD_HIGH;
RF_CS_LOW;
//GPIOC->CRL = 0x22222222; //2M 推挽输出
GPIOC->CRL = 0x33333333; //50M 推挽输出
GPIOC->ODR = (u16)data;
Delay(0x1f);
RF_WR_HIGH;
RF_CS_HIGH;
RF_ALE_LOW;
RF_RD_HIGH;
}
u8 rf_read_data()
{
u8 data;
RF_ALE_LOW;
RF_WR_HIGH;
RF_RD_LOW;
RF_CS_LOW;
//GPIOE->CRL = 0xcccccccc; //输入
GPIOE->CRL = 0x44444444; //输入
data = (u8)(GPIOE->IDR);
RF_RD_HIGH;
RF_WR_HIGH;
RF_CS_HIGH;
RF_ALE_LOW;
return data;
}
void rf_init(void)
{
u8 data;
rf_gpio_init();
RF_RESET_HIGH;
Delay(0xaffff);
RF_RESET_LOW;
//RF_RESET_HIGH;
rf_write_cmd(0x01); //command
data = rf_read_data();
rf_write_cmd(0x02); //fifiData
rf_write_data(0xff);
rf_write_cmd(0x02);
data = rf_read_data();
rf_write_cmd(0x02); //fifiData
rf_write_data(0xfe);
rf_write_cmd(0x02);
data = rf_read_data();
} |