I2c in detail
Download
1 / 15

I2C in Detail - PowerPoint PPT Presentation


  • 98 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' I2C in Detail' - idra


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript



Write multiple bytes
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


Read multiple bytes
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)


Typical i2c peripheral tca6424 port expander
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.


Write data
Write Data

AI = Auto Increment


Read data
Read data

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


Wii nunchuck
Wii Nunchuck

  • x-y potentiometer

  • 3 axis accelerometer

  • 2 buttons

  • I2C (address = 0x52 = 82)


Nunchuck with i2c
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”


Data format
Data format

  • 6 Bytes

From: http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck


ad