1 / 15

I2C in Detail

I2C in Detail. I2C Block Diagram. Key for diagrams. Write multiple bytes. UCBxTXIFG is set when START condition is generated and first data can be written to UCBxTXBUF . UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition

idra
Download Presentation

I2C in Detail

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. I2C in Detail

  2. I2C Block Diagram

  3. Key for diagrams

  4. Write multiple bytes UCBxTXIFG is set when STARTcondition is generated and first data can be written to UCBxTXBUF. UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition while (!(IFG2 & UCB0TXIFG)); // Wait while IFG is low UCB0TXBUF = Byte1; // Load TX buffer (clears ifg) while (!(IFG2 & UCB0TXIFG)); // Wait for IFG UCB0TXBUF = Byte2; // Load TX buffer while (!(IFG2 & UCB0TXIFG)); // Wait for IFG : UCB0TXBUF = ByteN; // Load TX buffer while (!(IFG2 & UCB0TXIFG)); // Wait for IFG UCB0CTL1 |= UCTXSTP; // I2C stop condition IFG2 &= ~UCB0TXIFG; // Clear USCI_B0 TX intflag while (UCB0CTL1 & UCTXSTP); // Wait UCTXSTP to be clear (stop done) As soon as transmit starts, TXBUF is empty

  5. Read multiple bytes UCB0CTL1 &= ~UCTR; UCB0CTL1 |= UCTXSTT; // I2C RX, start condition while (UCB0CTL1 & UCTXSTT); // wait while UCTXSTT is clear for (i=0;i<N;i++) { while (!(IFG2 & UCB0RXIFG)); // Wait for byte to be available; inData[i] = UCB0RXBUF; // Read data (also clears IFG) if (i==(N-2)) UCB0CTL1 |= UCTXSTP; // I2C stop condition } while (UCB0CTL1 & UCTXSTP); // Wait for UCTXSTP to be clear (stop done)

  6. Typical I2C peripheral (TCA6424 port expander) • 24 bits of GPIO • Can generate interrupts on pin change • I2C Address (+ LSB for R/W): • 34 if ADDR=0 • 35 if ADDR=1 The details of the device are not that important to us.The general method of using I2C devices is important.

  7. Write Data AI = Auto Increment

  8. Read data Must write the command byte, and then switch to read mode to get the data. Note that R/W bit changes

  9. Wii Nunchuck • x-y potentiometer • 3 axis accelerometer • 2 buttons • I2C (address = 0x52 = 82)

  10. Nunchuck with I2C • Initialize: • Start condition • Write 0xF0 (register # on nunchuck) • Write 0x55 (command to nunchuck) • Stop Condition • Read nunchuck data • Start condition • Read six bytes • Stop condition • Initiate new read • Start condition • Write 0x00 (initiate new read) • Stop condition • Loop to “Read nunchuck data”

  11. Data format • 6 Bytes From: http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck

More Related