大家好:
我用的是勤研的AT91RM9200开发板,跑linux 2.6.10的系统,现在在调RTC。用的是I2C接口的PCF8563,用示波器看过输入波形、SCL、SDA都有。问题是不管用勤研给的测试程序还是Atmel的eeprom测试程序都不行,不管写入什么读出来都是0。请有调出来的兄弟指条明路!
小弟先谢了!
已经搞定了。
1:始终频率的问题,可以是400K、300K或200K,但是100K不行。
2:I2C读写的问题,更改后如下:
int AT91F_TWI_Write(const AT91PS_TWI pTwi ,int address, char *data2send, int size)
{
unsigned int status, nb_trial;
// Set the TWI Master Mode Register
pTwi->TWI_MMR = ( AT91C_EEPROM_I2C_ADDRESS | AT91C_TWI_IADRSZ_1_BYTE ) & ~AT91C_TWI_MREAD;
// Set TWI Internal Address Register
pTwi->TWI_IADR = address;
status = pTwi->TWI_SR;
pTwi->TWI_THR = *(data2send++);
pTwi->TWI_CR = AT91C_TWI_START | AT91C_TWI_STOP;
nb_trial = 0;
status = pTwi->TWI_SR;
while (!( status & AT91C_TWI_TXCOMP) && (nb_trial < 10)) {
nb_trial++;
if (status & AT91C_TWI_ERROR) {
// Si Under run OR NACK Start again
pTwi->TWI_CR = (unsigned int) (AT91C_TWI_START | AT91C_TWI_STOP);
// Program temporizing period (300us)
}
}
// Wait transfer is finished
while (!(pTwi->TWI_SR & AT91C_TWI_TXCOMP));
return AT91C_EEPROM_WRITE_OK;
}
//*=========================================================
//* READ
//*=========================================================
//*----------------------------------------------------------------------------
//* \fn AT91F_TWI_Read
//* \brief Read n bytes from a slave device
//*----------------------------------------------------------------------------
int AT91F_TWI_Read(const AT91PS_TWI pTwi , int address, char *data, int size)
{
unsigned int status, nb_trial;
// Set the TWI Master Mode Register
pTwi->TWI_MMR = AT91C_EEPROM_I2C_ADDRESS | AT91C_TWI_IADRSZ_1_BYTE | AT91C_TWI_MREAD;
// Set TWI Internal Address Register
pTwi->TWI_IADR = address;
// Start transfer
pTwi->TWI_CR = AT91C_TWI_START | AT91C_TWI_STOP;
nb_trial = 0;
status = pTwi->TWI_SR;
while (!(status & AT91C_TWI_TXCOMP) && (nb_trial < 10)) {
nb_trial++;
status = pTwi->TWI_SR;
}
status = pTwi->TWI_SR;
// Wait transfer is finished
while (!(pTwi->TWI_SR & AT91C_TWI_TXCOMP));
// Read last byte
*data = pTwi->TWI_RHR;
return AT91C_EEPROM_READ_OK;
}
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |