Author Topic: Problem with 24LC256 & Atmega16 read/write & strange wave form on Rigol DS1054Z  (Read 2317 times)

0 Members and 1 Guest are viewing this topic.

Offline topksharma@gmail.comTopic starter

  • Newbie
  • Posts: 3
  • Country: no
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: [Select]
#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 0xA1

void i2c_init()
{
//set SCL to 100kHz
// CPU freq = 2MHz
TWSR = 0x00;
TWBR = (1<<TWPS1);
//enable TWI
TWCR = (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;
}


« Last Edit: April 26, 2017, 03:41:42 pm by topksharma@gmail.com »
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1613
  • Country: gb
No attachment.

Also a schematic would be nice, I occasionally see people using I2C without pull-up resistors.
 

Online hexreader

  • Frequent Contributor
  • **
  • Posts: 262
  • Country: england
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
« Last Edit: April 26, 2017, 04:25:48 pm by hexreader »
 

Offline topksharma@gmail.comTopic starter

  • Newbie
  • Posts: 3
  • Country: no
Connecting only SDA and SCL is not enough - you also need ground connections.

50mV and 10mV per division vertical is far to 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

I have connected other end of the probe to GND as well.
 

Offline topksharma@gmail.comTopic starter

  • Newbie
  • Posts: 3
  • Country: no
Connecting only SDA and SCL is not enough - you also need ground connections.

50mV and 10mV per division vertical is far to 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

Everything seems correct to me, just don't know why it's not working.. 
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
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! 
The easiest person to fool is yourself. -- Richard Feynman
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf