Problem with 24LC256 & Atmega16 read/write & strange wave form on Rigol DS1054Z - Page 1
Forum section: electronics / beginners

author: topksharma@gmail.com
author_rank: Newbie
timestamp: April 26, 2017, 01:55:16 pm
content: Hi All,I am very beginner to electronics.I have experience with software development but no experience with electronics.I have learned everything on my own from last 3-4 moths.I am trying to write to and read from 24LC256 chip with Atmega16.In my program I don't get any error , program runs good but I don't read what I write I always read 0xFF which is default value.So to find out more about this I actually bought an Rigol DS1054Z, after connecting probes to SDA & SCL I get a very strange wave form, I have attached a picture of the wave form.I expected to see a wave form which has a straight line and then goes low or high, I mean same which we see on images where we learn about I2C protocol.I can share my code and bread board connections if needed.I can try whatever you guys think may go wrong.Please help me in finding/troubleshoot the problem.Here is my code which I am using.Code:#ifndef F_CPU// if F_CPU was not defined in Project -> Properties#define F_CPU 2000000UL// define it now as 2 MHz unsigned long#endif#include <avr/io.h>#include<avr/interrupt.h>#include "util/delay.h"#define EEPROM_WRITE 0xA0#define EEPROM_READ 0xA1void i2c_init(){//set SCL to 100kHz// CPU freq = 2MHzTWSR = 0x00;TWBR = (1<<TWPS1);//enable TWITWCR = (1<<TWEN);}void i2c_start(){TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);while ((TWCR & (1<<TWINT)) == 0);}void i2c_stop(){TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN);_delay_ms(100);}void i2c_write(uint8_t u8data){TWDR = u8data;TWCR = (1<<TWINT)|(1<<TWEN);while ((TWCR & (1<<TWINT)) == 0);_delay_ms(10);}uint8_t i2c_read(){TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA);while ((TWCR & (1<<TWINT)) == 0);return TWDR;}int main(){i2c_init();uint8_t readByte=0;uint16_t address=0x0;uint8_t writeVal=0;while (1){i2c_start();i2c_write(EEPROM_WRITE);i2c_write(address>>8);i2c_write(address & 0xFF);i2c_write(writeVal);i2c_stop();writeVal++;address++;address=0;//for (int a =0;a<128;a++)//{i2c_start();i2c_write(EEPROM_READ);i2c_write(address>>8);i2c_write(address & 0xFF);readByte =i2c_read();_delay_ms(10);i2c_stop();address++;_delay_ms(500);}return 0;}

author: Buriedcode
author_rank: Super Contributor
timestamp: April 26, 2017, 01:59:08 pm
content: No attachment.Also a schematic would be nice, I occasionally see people using I2C without pull-up resistors.

author: hexreader
author_rank: Frequent Contributor
timestamp: April 26, 2017, 02:09:34 pm
content: Connecting only SDA and SCL is not enough - you also need ground connections.50mV and 10mV per division vertical is far too sensitive - set vertical sensitivity to 2V per division and make sure x1 or x10 is set on scope to match the setting on your probes

author: topksharma@gmail.com
author_rank: Newbie
timestamp: April 26, 2017, 03:43:07 pm
content: Quote from: hexreader on April 26, 2017, 02:09:34 pmI have connected other end of the probe to GND as well.

author: topksharma@gmail.com
author_rank: Newbie
timestamp: April 26, 2017, 04:14:58 pm
content: Quote from: hexreader on April 26, 2017, 02:09:34 pmEverything seems correct to me, just don't know why it's not working..

author: alsetalokin4017
author_rank: Super Contributor
timestamp: April 27, 2017, 04:33:05 am
content: Your scope is set incorrectly for the signal you are trying to read.Your vertical scale is set far too sensitive, and your horizontal scale appears to be set at 10 ns/div. You are just reading noise at those settings. Avoid the "Auto" key in the top row and manually set your scope's horizontal and vertical settings to something that makes sense for your anticipated signal.You know you are supposed to be reading something that goes Low and High somewhere between 0 and 5 V volts, right? So you certainly do not want 50 or 10 mV per division vertically. And your horizontal time/division should be set to something that makes sense for the pulse rate (frequency) you anticipate. Surely it will be much slower than 100 MHz!