软件读取rfid成功
This commit is contained in:
@ -14,11 +14,25 @@
|
||||
#define xlog(format, ...) ((void)0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
IFSEL1 IFSEL0 Host_Interface
|
||||
0 0 UART
|
||||
1 0 SPI
|
||||
0 1 IIC
|
||||
1 1 SPI
|
||||
INTERFACE_TYPE == 0:iic
|
||||
== 1: spi
|
||||
== 2: uart
|
||||
*/
|
||||
#define INTERFACE_TYPE 0
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
#if INTERFACE_TYPE == 0 //iic接口
|
||||
/*
|
||||
注:iic读取rfid不建议使用底层的硬件iic,很容易造成程序崩溃,并且时序有时候对不上会造成读写信息错误
|
||||
这里利用底层写好的软件iic接口来实现寄存器的读写
|
||||
*/
|
||||
|
||||
/*
|
||||
IF2 IF0 ADDR
|
||||
@ -50,11 +64,23 @@ unsigned char FM176XX_HardInit(void){
|
||||
* 接口:iic
|
||||
*/
|
||||
unsigned char GetReg(unsigned char address, unsigned char *reg_data){
|
||||
if(_gravity_sensor_get_ndata(FM176_READ_ADDR, address, reg_data, 1)){
|
||||
return SUCCESS;
|
||||
}else{
|
||||
soft_iic_start(0);
|
||||
if (0 == soft_iic_tx_byte(0, FM176_WRITE_ADDR)) {
|
||||
soft_iic_stop(0);
|
||||
return FAIL;
|
||||
}
|
||||
if (0 == soft_iic_tx_byte(0, address)) {
|
||||
soft_iic_stop(0);
|
||||
return FAIL;
|
||||
}
|
||||
soft_iic_start(0);
|
||||
if (0 == soft_iic_tx_byte(0, FM176_READ_ADDR)) {
|
||||
soft_iic_stop(0);
|
||||
return FAIL;
|
||||
}
|
||||
*reg_data = soft_iic_rx_byte(0, 0);
|
||||
soft_iic_stop(0);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@ -67,11 +93,21 @@ unsigned char GetReg(unsigned char address, unsigned char *reg_data){
|
||||
* 接口:iic
|
||||
*/
|
||||
unsigned char SetReg(unsigned char address, unsigned char reg_data){
|
||||
if(gravity_sensor_command(FM176_WRITE_ADDR, address, reg_data) == 0){
|
||||
soft_iic_start(0);
|
||||
if (0 == soft_iic_tx_byte(0, FM176_WRITE_ADDR)) {
|
||||
soft_iic_stop(0);
|
||||
return FAIL;
|
||||
}else{
|
||||
return SUCCESS;
|
||||
}
|
||||
if (0 == soft_iic_tx_byte(0, address)) {
|
||||
soft_iic_stop(0);
|
||||
return FAIL;
|
||||
}
|
||||
if (0 == soft_iic_tx_byte(0, reg_data)) {
|
||||
soft_iic_stop(0);
|
||||
return FAIL;
|
||||
}
|
||||
soft_iic_stop(0);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user