Lecture13_I2C_handou - I2C_lecture Coding Example Repeat data byte for num_bytes-1 times Followed by last write with a stop bit void

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
I2C_lecture October 10, 2007 1 19 October 10, 2007 Lecture #13 - Blimp Coding Example void i2c_write_data(unsigned char dev_addr, unsigned char start_reg, unsigned char *buffer, unsigned char num_bytes) { unsigned char j; i2c_start(); //start i2c i2c_write(dev_addr&~0x01); //identify target and send 0 in R/W bit i2c_write(start_reg); //Specify device register to be written for(j=0; j<num_bytes-1; j++) //write all but last data byte i2c_write(buffer[j]); i2c_write_and_stop(buffer[num_bytes-1]); //write last data byte and stop } Repeat data byte for num_bytes-1 times Followed by last write with a stop bit. 20 October 10, 2007 Lecture #13 - Blimp Coding Example – you write this one, work sheet #8 void i2c_read_data(unsigned char addr, unsigned char start_reg,unsigned char *buffer, unsigned char num_bytes) { Start I2C transfer Write the address of the device to read from Stop and write the first register to be read Start I2C transfer Write address again, this time indicating a read operation For (0 to num_bytes – 2) Set acknowledge bit Read data, save it in the buffer Clear acknowledge bit Read the last byte and stop, save it in the buffer }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
I2C_lecture October 10, 2007 1 14 October 10, 2007 Lecture #13 - Blimp Run at about 100kHz, done once ± SMB0CR=0x93; Set the crossbar, done once ± XBR0= 0x**; /* use setting from lab 3, part 1 */ Enable the SMBus, (I2C), done once ± ENSMB=1; /* bit 6 of SMB0CN */ For everything else, we need to read and write to the sfr’s. 16 October 10, 2007 Lecture #13 - Blimp Implementing the I2C Need two higher level functions ± void write_data (unsigned char addr, unsigned char slave_reg, unsigned char *buffer, unsigned char num_bytes)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/08/2011 for the course ENGR 2350 taught by Professor Fukanari during the Spring '08 term at Rensselaer Polytechnic Institute.

Page1 / 4

Lecture13_I2C_handou - I2C_lecture Coding Example Repeat data byte for num_bytes-1 times Followed by last write with a stop bit void

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online