附上我写的代码请教XDT512片内I2C问题[求助][讨论]
- UID
- 139803
- 性别
- 男
|
附上我写的代码请教XDT512片内I2C问题[求助][讨论]
我再程序里先写满1片24C02,再把里面的内容读到片内RAM中.
虽然能正确写进去了,但是读的时候总是读出256个0xFF
请大家帮忙看看什么问题 !!!!!!!
/***********************************************************/ void I2C0_init(void) { unsigned char i; re_send_sladd=0;//it's used in the begin of the read to send the slave address again acording the I2C protocol i2c_step=0;//use this semaphore to control the cycle of read and write new_inner_page=1;//1 means a new page is begin,0 means the old page is not finished i2c_page_counter=0;//24c02 has 32 pages with 8 byte per page byte_write_conter=0; I2C_frequency_define=0xBF;//use the lowest clock in debug I2C_control_address_length=0;//use 7bit addressing I2C_start; i=I2C_data;//dummy read from IBDR register } /***********************************************************/ void I2C0_start(unsigned char mode_select,unsigned char add_24c02,unsigned char direc_control){ while((I2C_status&0x20)>>5==1);//wait for the bus idle I2C_control|=(0x41|mode_select);//interrupt enable,master,transmit,acknowledge if need I2C_data=add_24c02|direc_control;//slave address and write to slave while((I2C_status&0x20)>>5!=1);//ensure the bus is engrossed by it } /***********************************************************/ void main(void) { SetupXGATE(); I2C0_init(); interrupt_init(); EnableInterrupts;
for(;;) { switch(i2c_step) { case 0: i2c_step=1; I2C0_start(master_write,i2c_chip_add,write);//generate START,send slave address;master write break; case 1: break; case 2: i2c_step=1; if(re_send_sladd==0){ //the first time to send 24C02's address re_send_sladd=1;//make the following ISR switch to "case master_r_select_add" I2C0_start(master_write,i2c_chip_add,write); } else if(re_send_sladd==2){ re_send_sladd=0; I2C_control&=0xEF;//clear the Tx/Rx bit to select receive mode Repeat_start;//generate repeat start I2C_data=i2c_chip_add|read; } else{;} break; default:{;} }//end of switch }//end of the loop }//end of main |
|
|
|
|
|
- UID
- 139803
- 性别
- 男
|
|
|
|
|
|