Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] 24C32 read and write isses

Status
Not open for further replies.

Rendon

Newbie level 4
Joined
Jun 23, 2012
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
South Africa
Activity points
1,340
I cannot seem to write to this device. I am using library protocols in MikroC to address this device. I am able to address the smaller 24C02 without any difficulty. I have a small veroboard with 3 I^2C devices + dip switch arrays to preset device addresses.

I know that the 24C32 is addressed correctly because it returns a value of 255 only when its address corresponds to my variable set in code. If I remove the device or change its address, it does not return the value of 255. I am using the identical protocol as I do with the 24C02. There is no change in code. I am prefixing the device address with 1010 ****. The ONLY difference is the chip. Below is my code. I am using eeprom data address #9. Initially, I thought the device might be faulty, so I swapped it out, but to no avail. The value in variable "test" is what I am trying to write to the 24C32. Again, this code works perfectly on the 24C02. Any idea as to why that is? I'm stumped. (These are both Atmel devices.)


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
char   atmel4 = 0xa6,  test=0x77,      
 
 
 
void main(){
 
  PORTB = 0;
  TRISB = 0;                 // Configure PORTB as output
 
  I2C1_Init(100000);         // initialize I2C communication
  
//write protocol
  
  I2C1_Start();              // issue I2C start signal
  I2C1_Wr(atmel4);             // send byte via I2C  (device address + W)
  I2C1_Wr(9);                // send byte (address of EEPROM location)
  I2C1_Wr(test);             // send data (data to be written)
  I2C1_Stop();               // issue I2C stop signal
 
  
//Read protocol
 
  Delay_100ms();
 
  I2C1_Start();              // issue I2C start signal
  I2C1_Wr(atmel4);             // send byte via I2C  (device address + W)
  I2C1_Wr(9);                // send byte (data address)
  I2C1_Repeated_Start();     // issue I2C signal repeated start
  I2C1_Wr(atmel4+1);             // send byte (device address + R)
  PORTB = I2C1_Rd(0u);       // Read the data (NO acknowledge)
  I2C1_Stop();               // issue I2C stop signal
}

 
Last edited by a moderator:

Dont let the control exit the main()

- - - Updated - - -

Dont let the control exit the main()
 

Do you mean don't use library functions? I am new to C.

- - - Updated - - -

Do you mean don't use library functions? I am new to C.
 

I think he means:

Code C - [expand]
1
2
3
4
5
6
7
void main(){
 
// Your code
 
while(1){};     // <-- add this at the bottom of your code
 
}



When your code needs to loop:

Code C - [expand]
1
2
3
4
5
6
7
8
void main(){
 
while(1){
 
// Code here
 
    };
}

 
Last edited:

Yes. When you run a C program in a PC, the OS takes control when your program ends. But that does not happen in case of a microcontroller. And the mc becomes unstable(kind of).
There may be other problems in your code but correct the structure of the program first.
 

you have 2 address bytes in 24C32 not 1 like in the 24c02
 

Yes, you're absolutely right. It occurred to me while I was trying to sleep. I got up and added a second address write and it solved the problem.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top