Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

E²PROM Serial Memory

Status
Not open for further replies.

EN0

Member
Hello,

I'm trying to write to this serial E²PROM device, the 24AA08, and I can't get it working! Here's my code:

Code:
/************************************************************************
*
* Module:       Serial_E²PROM_1.C
* Description:  Code to test serial E²PROM functionality.
* Line length:  120 characters [only if the length is longer than 80 chars]
* Functions:    Void
*
* Date:	      Author:		Comments:
* 12 Jun 2011   Austin Schaller    	Created
*
************************************************************************/


#include <p18f4220.h>
#include <delays.h>
#include <i2c.h>
#pragma config OSC=INTIO2, WDT=OFF, LVP=OFF, DEBUG=ON

//** Defines ***********************************************************
#define		CONTROL		0xA0		// Control nibble + (B1 = 0) + (B2 = 0)
#define		ADDRESS		0x00		// Start from the beginning
#define		DATA		0xFF		// Arbitrary

#define		DEL05S		Delay10KTCYx(100)		//Delay 0.5 seconds
#define		DEL1S		Delay10KTCYx(200)		// Delay 1 econd


void main(void)
{
	// Variable Declarations
	int i, ack;
	
	// Oscillator settings
	OSCCON = 0x70;		// OSC = 8 MHz
	while(!OSCCONbits.IOFS);		// Wait for OSC to be ready
	
	TRISAbits.TRISA0 = 0;		// RA0 as  output
	TRISC = 0x0C;		// RC3 = SCL, RC4 = SDA
	
	OpenI2C(MASTER, SLEW_OFF);
	SSPADD = 4;		/* 400 kHz baud @ 8 MHz
					Clock = ((Fosc/CLK)/4) - 1*/
	
	// Write to serial E²PROM
	EEByteWrite(CONTROL, ADDRESS, DATA);
	ack = EEAckPolling(CONTROL);

	if(!ack)
	{
		// Blink status LED five times
		for(i = 0; i < 5; i++)
		{
			LATAbits.LATA0 = ~LATAbits.LATA0;		// Invert sign of RA0
			DEL05S;		// Delay half a second
		}
	}
	else
	{
		// Show nothing, NOTHING!
		LATAbits.LATA0 = 0;
	}
}

I can see data pulses on my SDA line, but not SCL. I've spent a lot of time on this and just can't figure what's going on!

Hopefully one of you can!

Thanks,

Austin
 
I didn't know that A0, A1, and A2 needed to be pulled to ground! That's probably my issue.

Eventually I would like to write my own serial libraries, but due to time constraints at the moment, I'm just going to use Microchip's routine.
 
I reconfigured the hardware, tried doing it again, but my attempt was futile!

What's going on?
 
I did a little debugging and stepped through the code I have in addition to the EEByteWrite() and EEAckPolling(). It stopped at this point:

Code:
  if ( PIR2bits.BCLIF )           // test for bus collision
  {
    return ( -1 );                // return with Bus Collision error 
  }

I went ahead and double-checked the PIR2 register and confirmed that it read 0x08, thus giving me a bus collision error.

Evidently, something was actively inconsistent on the I²C bus, so upon further inspection, I found that one of my pullup resistors was connected to Vss!

So I fixed that hardware issue and now it is successful!

I need to pay more close attention, but thanks for your help guys!
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top