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:
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'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