Advertisement
Guest User

Untitled

a guest
Dec 29th, 2010
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1.     while(I2C_GetFlagStatus (I2C_ITG3200, I2C_FLAG_BUSY));
  2.     /* Send START condition */
  3.     I2C_GenerateSTART (I2C_ITG3200, ENABLE);
  4.     /* Test on EV5 and clear it */
  5.     while (!I2C_CheckEvent(I2C_ITG3200, I2C_EVENT_MASTER_MODE_SELECT));
  6.     /* Send EEPROM address for write */
  7.     I2C_Send7bitAddress (I2C_ITG3200, ITG3200_SLAVE_ADDR, I2C_Direction_Transmitter);
  8.     /* Test on EV6 and clear it */
  9.     while (!I2C_CheckEvent (I2C_ITG3200, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
  10.     /* Send the EEPROM's internal address to write to */
  11.     I2C_SendData (I2C_ITG3200, addr);
  12.     /* Test on EV8 and clear it */
  13.     while (!I2C_CheckEvent (I2C_ITG3200, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
  14.     /* Send STRAT condition a second time */  
  15.     I2C_GenerateSTART (I2C_ITG3200, ENABLE);
  16.     /* Test on EV5 and clear it */
  17.     while (!I2C_CheckEvent (I2C_ITG3200, I2C_EVENT_MASTER_MODE_SELECT));
  18.     /* Send EEPROM address for read */
  19.     I2C_Send7bitAddress (I2C_ITG3200, ITG3200_SLAVE_ADDR, I2C_Direction_Receiver);
  20.     /* Test on EV6 and clear it */
  21.     while (!I2C_CheckEvent (I2C_ITG3200, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
  22.  
  23.     unsigned short t = 0xfff;
  24.     while (t --);
  25.  
  26.     while (!I2C_CheckEvent (I2C_ITG3200, I2C_EVENT_MASTER_BYTE_RECEIVED));
  27.    
  28.     I2C_AcknowledgeConfig (I2C_ITG3200, DISABLE);       /* Disable Acknowledgement */
  29.  
  30.     /* Read a byte from the EEPROM */
  31.     *buf = I2C_ReceiveData (I2C_ITG3200);
  32.  
  33.     t = 0xfff;
  34.     while (t --);
  35.  
  36.     I2C_GenerateSTOP (I2C_ITG3200, ENABLE);         /* Send STOP Condition */
  37.  
  38.     /* Enable Acknowledgement to be ready for another reception */
  39.     I2C_AcknowledgeConfig (I2C_ITG3200, ENABLE);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement