Beating down I2C

A project log for MiniSam-Zero

Tiny sameD09 dev board. (Zero has nothing to do with arduino, the name allows other boards in this line. namely -One, & -Two coming later.)

Jeremy g.Jeremy g. 08/09/2016 at 07:160 Comments

Finaly.. after a small break, playing some much needed video games. I finaly got i2c to play nice with the samd09 not using asf drivers.

It's still a bit finicky, I have to get the wait states right (delays) since the eeprom takes a while to write each byte.

New board

Writing 0xef

Reading beef, I wrote deadbeef to the eeprom earlier while testing the write byte functions.

I'll update the repository and start nailing down the i2c library, as well as making a library for the 24lcxxx eeproms.

update #1

Seems I broke it again... but learned a bit about how the i2c module works. And also seemed to have sudo fixed it at the same time.

I was reading the datasheet for the 24lc256 wrong and read the 8 byte word section as a 16 byte word for some reason.

So (a reminder for me) to write a byte worth of data in byte right mode we need too.

/*address space is from 0x0000 to 0x7FFF */

/*write a byte of something*/
I2c_write_start (); //starts a write transaction [send start,address,and w/r bit]
I2c_write_byte (0x00); //write data address high byte.
I2c_write_byte (0x00); //write data address low byte address 0x0000 00000
I2c _write_byte (0xAA); //write one byte of data at the supplied address
I2c_write_stop (); //send stop bit.

/*read a byte from the eeprom.*/
i2c_write_start(); // this sends the address with a w bit
i2c_write_byte(); // write data address high byte.
i2c_write_byte(); // write data address low byte.
i2c_read(data,1); // sends address with r bit, read from the data register, this reads two bytes, needs to be fixed.

/*put it on the serial terminal.*/

All of this should work, I just now added some functions to this block of code. As I was not sending the start address for the read command just the address and r bit. I will update more later. Once I get this working I will write a 24lcxxx library that uses this i2c library for easier commands.

update #2

I got the i2c library nailed down for now. And started on the generic eeprom library. So far I can write a 16 byte word or 8 bytes to the eeprom, I can read it back. I can page write to the eeprom, reading back the page is proving to be difficult for some reason. I need to split the i2c read function apart.

Data! corrupted my photos... I'll be back with some pics...