RC522 读取寄存器便宜一个字节
使用MSP430SPI口读取RC522寄存器时出现错位,如下表UART发送正常##########
测试SIP口通讯.....
RC522_REG = 0x1e
RC522_REG = 0x 0
RC522_REG = 0x20
RC522_REG = 0x80
RC522_REG = 0x 0
RC522_REG = 0x14
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x21
RC522_REG = 0x 0
RC522_REG = 0x80
RC522_REG = 0x 0
RC522_REG = 0x 8
RC522_REG = 0x10
RC522_REG = 0x 0
RC522_REG = 0xa0
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x3f
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x80
RC522_REG = 0x 0
RC522_REG = 0x10
RC522_REG = 0x84
RC522_REG = 0x84
RC522_REG = 0x4d
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x62
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0xeb
RC522_REG = 0x 0
RC522_REG = 0xff
RC522_REG = 0xff
RC522_REG = 0x88
RC522_REG = 0x26
RC522_REG = 0x87
RC522_REG = 0x48
RC522_REG = 0x88
RC522_REG = 0x20
RC522_REG = 0x20
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x90
RC522_REG = 0x6b
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x80
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x40
RC522_REG = 0x91
RC522_REG = 0x 0
RC522_REG = 0x 1
RC522_REG = 0x 2
RC522_REG = 0x88
RC522_REG = 0xff
RC522_REG = 0x 0
RC522_REG = 0x 3
unsigned char ReadRegRC1(unsigned char ucAddress)
{
Spi_SendByte((ucAddress<<1)&0x7E|0x80);// 发送读取寄存器地址(最低位为0,中间6位为实际地址,最高位为1)
return (Spi_RecvByte());
}
void Spi_SendByte(unsigned char ucData)
{
RC522_NSS_0();
UCB0TXBUF = ucData;
while ((IFG2 & UCB0TXIFG) == 0); // 等待一个字节发送完成
RC522_NSS_1();
}
RC522官方手册中描述寄存器地址 0x37,是版本号。应该为0x91,但见上表。怎么跑到0x38去了????????????????????
9.3.4.8 VersionReg register
Shows the MFRC522 software version.
MFRC522 version 1.0 software version is: 91h.
MFRC522 version 2.0 software version is: 92h.
UART发送正常##########
测试SIP口通讯.....
RC522_REG = 0x 0
RC522_REG = 0x20
RC522_REG = 0x80
RC522_REG = 0x 0
RC522_REG = 0x14
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x21
RC522_REG = 0x 0
RC522_REG = 0xc2
RC522_REG = 0x 0
RC522_REG = 0x 8
RC522_REG = 0x10
RC522_REG = 0x 0
RC522_REG = 0xa0
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x3f
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x80
RC522_REG = 0x 0
RC522_REG = 0x10
RC522_REG = 0x84
RC522_REG = 0x84
RC522_REG = 0x4d
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x62
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0xeb
RC522_REG = 0x 0
RC522_REG = 0xff
RC522_REG = 0xff
RC522_REG = 0x88
RC522_REG = 0x26
RC522_REG = 0x87
RC522_REG = 0x48
RC522_REG = 0x88
RC522_REG = 0x20
RC522_REG = 0x20
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x93
RC522_REG = 0xa9
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x80
RC522_REG = 0x 0
RC522_REG = 0x 0
RC522_REG = 0x40
RC522_REG = 0x91
RC522_REG = 0x 0
RC522_REG = 0x27
RC522_REG = 0x 2
RC522_REG = 0x88
RC522_REG = 0xff
RC522_REG = 0x 0
RC522_REG = 0x 3
RC522_REG = 0x 0
现在可以了,但是奇怪的是。写寄存器为什么写不进去。大家帮我看看。
void WriteRawRC1(unsigned char ucAddress, unsigned char ucValue)
{
Spi_SendByte((ucAddress<<1)&0x7E);
Spi_SendByte(ucValue);
IFG2 &= ~UCB0TXIFG;
}
/*****************************************************************************
** Function name: Spi_RecvByte
**
** Descriptions: 通过UART接收一个字节数据
** parameters: buffer pointer, and data length
** Returned value: None
**
*****************************************************************************/
unsigned char Spi_RecvByte(void)
{
RC522_NSS_0();
while((IFG2 & UCB0RXIFG) == 0); // 等待接收一个字节数据
RC522_NSS_1();
return(UCB0RXBUF);
} /*****************************************************************************
** Function name: Spi_SendByte
**
** Descriptions: 通过UART输出一个BYTE的数据
** parameters: ucData
** Returned value: None
**
*****************************************************************************/
void Spi_SendByte(unsigned char ucData)
{
RC522_NSS_0();
UCB0TXBUF = ucData;
while ((IFG2 & UCB0TXIFG) == 0); // 等待一个字节发送完成
RC522_NSS_1();
}
页:
[1]