Mình đang làm mạch thu FM dùng 8051 và chip RDA5807 nhưng tới phần cấu hình các thanh ghi cho con RDA thì làm mãi nó không chịu chạy
mình đọc datasheet của nó và cấu hình như sau
mọi người vào xem giúp mình code sai ở chổ nào
datasheet con này RDA Microelectronics
mình đọc datasheet của nó và cấu hình như sau
void Write_Page_To_RDA(unsigned char* pData,unsigned char NoOfBytes)
{
unsigned int i;
I2C_Start(); // Start i2c communication
I2C_Write_Byte(0x20);
for(i=0;i<NoOfBytes;i++)
{ // Write NoOfBytes
I2C_Write_Byte(pData[i]);
I2C_Send_ACK(); // Write data byte
}
I2C_Stop(); // Stop i2c communication
}
// Function Purpose: Read_Bytes_From_RDA reads a NoOfBytes bytes from given starting address.
// Address can have any value fromm 0 to 0x1FFF. Also, NoOfBytes can have any value 0 to 0x1FFF.
// Read bytes are returned in pData array.
void Read_Bytes_From_RDA(unsigned char* pData, unsigned int NoOfBytes)
{
unsigned int i;
I2C_Start(); // Start i2c communication
// Send i2c address of with write command
I2C_Write_Byte(0x21);
for(i=0;i<NoOfBytes;i++) // Read NoOfBytes
{
pData[i] = I2C_Read_Byte(); // Read next byte from EEPROM
}
// Make SCK low, so that slave can stop driving SDA pin
// Send a NACK to indiacate read operation is complete
I2C_Send_NACK();
I2C_Stop();
{
unsigned int i;
I2C_Start(); // Start i2c communication
I2C_Write_Byte(0x20);
for(i=0;i<NoOfBytes;i++)
{ // Write NoOfBytes
I2C_Write_Byte(pData[i]);
I2C_Send_ACK(); // Write data byte
}
I2C_Stop(); // Stop i2c communication
}
// Function Purpose: Read_Bytes_From_RDA reads a NoOfBytes bytes from given starting address.
// Address can have any value fromm 0 to 0x1FFF. Also, NoOfBytes can have any value 0 to 0x1FFF.
// Read bytes are returned in pData array.
void Read_Bytes_From_RDA(unsigned char* pData, unsigned int NoOfBytes)
{
unsigned int i;
I2C_Start(); // Start i2c communication
// Send i2c address of with write command
I2C_Write_Byte(0x21);
for(i=0;i<NoOfBytes;i++) // Read NoOfBytes
{
pData[i] = I2C_Read_Byte(); // Read next byte from EEPROM
}
// Make SCK low, so that slave can stop driving SDA pin
// Send a NACK to indiacate read operation is complete
I2C_Send_NACK();
I2C_Stop();
void I2C_Send_ACK(void)
{
Set_SCK_Low; // Make SCK pin low
__delay_us(HalfBitDelay/2); // Data pin should change it's value,
// when it is confirm that SCK is low
Set_SDA_Low; // Make SDA Low
__delay_us(HalfBitDelay/2); // 1/4 bit delay
Set_SCK_High; // Make SCK pin high
__delay_us(HalfBitDelay); // Half bit delay
}
//Function : I2C_Send_NACK sends NACK bit sequence
void I2C_Send_NACK(void)
{
Set_SCK_Low; // Make SCK pin low
__delay_us(HalfBitDelay/2); // Data pin should change it's value,
// when it is confirm that SCK is low
Set_SDA_High; // Make SDA high
__delay_us(HalfBitDelay/2); // 1/4 bit delay
Set_SCK_High; // Make SCK pin high
__delay_us(HalfBitDelay); // Half bit delay
}
// Function Purpose: I2C_Write_Byte transfers one byte
unsigned char I2C_Write_Byte(unsigned char Byte)
{
unsigned char i; // Variable to be used in for loop
for(i=0;i<8;i++) // Repeat for every bit
{
Set_SCK_Low; // Make SCK pin low
__delay_us(HalfBitDelay/2); // Data pin should change it's value,
// when it is confirm that SCK is low
if((Byte<<i)&0x80) // Place data bit value on SDA pin
Set_SDA_High; // If bit is high, make SDA high
else // Data is transferred MSB first
Set_SDA_Low; // If bit is low, make SDA low
__delay_us(HalfBitDelay/2); // Toggle SCK pin
Set_SCK_High; // So that slave can
__delay_us(HalfBitDelay); // latch data bit
}
// Get ACK from slave
Set_SCK_Low;
Set_SDA_High;
__delay_us(HalfBitDelay);
Set_SCK_High;
__delay_us(HalfBitDelay);
return SDA;
}
// Function Purpose: I2C_Read_Byte reads one byte
unsigned char I2C_Read_Byte(void)
{
unsigned char i, d, RxData = 0;
for(i=0;i<8;i++)
{
Set_SCK_Low; // Make SCK pin low
Set_SDA_High; // Don't drive SDA
__delay_us(HalfBitDelay); // Half bit delay
Set_SCK_High; // Make SCK pin high
__delay_us(HalfBitDelay/2); // 1/4 bit delay
d = SDA; // Capture Received Bit
RxData = RxData|(d<<(7-i)); // Copy it in RxData
__delay_us(HalfBitDelay/2); // 1/4 bit delay
}
return RxData; // Return received byte
}
{
Set_SCK_Low; // Make SCK pin low
__delay_us(HalfBitDelay/2); // Data pin should change it's value,
// when it is confirm that SCK is low
Set_SDA_Low; // Make SDA Low
__delay_us(HalfBitDelay/2); // 1/4 bit delay
Set_SCK_High; // Make SCK pin high
__delay_us(HalfBitDelay); // Half bit delay
}
//Function : I2C_Send_NACK sends NACK bit sequence
void I2C_Send_NACK(void)
{
Set_SCK_Low; // Make SCK pin low
__delay_us(HalfBitDelay/2); // Data pin should change it's value,
// when it is confirm that SCK is low
Set_SDA_High; // Make SDA high
__delay_us(HalfBitDelay/2); // 1/4 bit delay
Set_SCK_High; // Make SCK pin high
__delay_us(HalfBitDelay); // Half bit delay
}
// Function Purpose: I2C_Write_Byte transfers one byte
unsigned char I2C_Write_Byte(unsigned char Byte)
{
unsigned char i; // Variable to be used in for loop
for(i=0;i<8;i++) // Repeat for every bit
{
Set_SCK_Low; // Make SCK pin low
__delay_us(HalfBitDelay/2); // Data pin should change it's value,
// when it is confirm that SCK is low
if((Byte<<i)&0x80) // Place data bit value on SDA pin
Set_SDA_High; // If bit is high, make SDA high
else // Data is transferred MSB first
Set_SDA_Low; // If bit is low, make SDA low
__delay_us(HalfBitDelay/2); // Toggle SCK pin
Set_SCK_High; // So that slave can
__delay_us(HalfBitDelay); // latch data bit
}
// Get ACK from slave
Set_SCK_Low;
Set_SDA_High;
__delay_us(HalfBitDelay);
Set_SCK_High;
__delay_us(HalfBitDelay);
return SDA;
}
// Function Purpose: I2C_Read_Byte reads one byte
unsigned char I2C_Read_Byte(void)
{
unsigned char i, d, RxData = 0;
for(i=0;i<8;i++)
{
Set_SCK_Low; // Make SCK pin low
Set_SDA_High; // Don't drive SDA
__delay_us(HalfBitDelay); // Half bit delay
Set_SCK_High; // Make SCK pin high
__delay_us(HalfBitDelay/2); // 1/4 bit delay
d = SDA; // Capture Received Bit
RxData = RxData|(d<<(7-i)); // Copy it in RxData
__delay_us(HalfBitDelay/2); // 1/4 bit delay
}
return RxData; // Return received byte
}
datasheet con này RDA Microelectronics
Comment