Part Number: CC430F5137
Hi,
i am working with cc430f5137 based project. Here i am facing following problem actually i am trying to interfacing the EEPROM with Microcontroller via I2C protocal.
1. Here i am using software protocal for I2c communication and i am using following bits are P1.3 for SDA,P1.2 for SCL and P1.1 for WP.
2. First i am trying to send the address to eeprom for identify the slave, here successfully write the add and eeprom gave the ACK to master.
3 After that i am trying to send add word to it , here the eeprom didn't give the ACK to master.
this is the actual problem facing
EEPROM part no is : AT24LC024
Here i have attached my firmware details. Please help me.
/*******************************Main.c*************************************/
#include "cc430f5137.h"
#include "EEPROM.h"
#include <msp430.h>
//#include "TI_USCI_I2C_master.h"
unsigned int i=0;
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
UCSCTL3 |= SELREF_2; // Set DCO FLL reference = REFO
UCSCTL4 |= SELA_2; // Set ACLK = REFO
// Initialize DCO to 8MHz
__bis_SR_register(SCG0); // Disable the FLL control loop
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
UCSCTL1 = DCORSEL_5; // Set RSELx for DCO = 16MHz
UCSCTL2 = FLLD_1 + 249; // Set DCO Multiplier for 8MHz
// (N + 1) * FLLRef = Fdco
// (74 + 1) * 32768 = 8MHz
// Set FLL Div = fDCOCLK/2
__bic_SR_register(SCG0); // Enable the FLL control loop
__delay_cycles(250000);
Registers_write1();
Registers_read();
}
/******************************************************************************************/
/************************************EEPROM.c*****************************************/
#include "cc430f5137.h"
#include "EEPROM.h"
#define EEPROM_PAGE_SIZE 128 //64 //AT24C256 has 64-byte page size
unsigned char uart_buffer[35], ruart_buffer[35],rrbuffer[40],Internal_Flash_Values[40]={'1','2','3','4','5','6','7','8','9','0'};
//TI_CC_Wait(35); Delay time 5.6uS at DCO Running with 8MhZ
//TI_CC_Wait(70); Delay Time 11.2uS at DCO Running with 8MhZ
void TI_CC_Wait(unsigned int cycles)
{
while(cycles>15) // 15 cycles consumed by overhead
cycles = cycles - 6; // 6 cycles consumed each iteration
}
void start(void)
{
sdaout();
EEPROM_OUT |= SDA_EEPROM;
EEPROM_OUT |= SCL_EEPROM;
EEPROM_OUT &= ~SDA_EEPROM;
TI_CC_Wait(35);//delay 5.6uS
EEPROM_OUT &= ~SCL_EEPROM;
}
void stop(void)
{
sdaout();
EEPROM_OUT &= ~SDA_EEPROM;
EEPROM_OUT &= ~SCL_EEPROM;
EEPROM_OUT |= SCL_EEPROM;
TI_CC_Wait(35);//delay 5.6uS
EEPROM_OUT |= SDA_EEPROM;
}
void sendb(unsigned char c)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(c&0x80)
{
EEPROM_DIR |=SDA_EEPROM;
EEPROM_OUT |=SDA_EEPROM; //SDA=1
TI_CC_Wait(35);//delay 5.6uS
}
else
{
EEPROM_DIR |=SDA_EEPROM;
EEPROM_OUT&=~SDA_EEPROM; //SDA=0;
TI_CC_Wait(35);//delay 5.6uS
}
c=c<<1;
EEPROM_DIR |=SCL_EEPROM;
EEPROM_OUT |=SCL_EEPROM; // SCL=1;
TI_CC_Wait(35);//delay 5.6uS
EEPROM_DIR |=SCL_EEPROM;
EEPROM_OUT&=~SCL_EEPROM; //SCL=0;
TI_CC_Wait(35);//delay 5.6uS
}
}
unsigned char getack_ee(void)
{
unsigned char ack=0;
EEPROM_DIR |=SDA_EEPROM;
EEPROM_OUT |=SDA_EEPROM; //SDA=1
TI_CC_Wait(10);//delay 1.6uS
EEPROM_DIR |= SCL_EEPROM;
EEPROM_OUT &= ~SCL_EEPROM; //SCL=0;
TI_CC_Wait(35);//delay 5.6uS
EEPROM_DIR &= ~(SDA_EEPROM); //
EEPROM_DIR |= SCL_EEPROM;
EEPROM_OUT |= SCL_EEPROM; // SCL=1;
TI_CC_Wait(35);//delay 5.6uS
ack=(char)(EEPROM_IN & SDA_EEPROM);
EEPROM_DIR |= SCL_EEPROM;
EEPROM_OUT &= ~SCL_EEPROM; //SCL=0;
TI_CC_Wait(35);//delay 5.6uS
return (ack & SDA_EEPROM);
}
void Registers_write1(void)
{
int i;
EEPROM_DIR |= 0x0E;//0X07;
EEPROM_OUT &= ~EEPROM_WP;
TI_CC_Wait(35);
for (i=0;i<10;i++)
{
eeprom_w_byte(i,Internal_Flash_Values[i]);
TI_CC_Wait(35);
}
EEPROM_OUT |= EEPROM_WP;
TI_CC_Wait(35);
}
void eeprom_w_byte(unsigned char add,unsigned char value)
{
start(); // starting the i2c communication
sendb(0xA0); // sending the address of the device
if(getack_ee())
{
stop();
}
sendb(add); // sending the higher byte of the address word
if(getack_ee())
{
stop();
}
sendb(value); // sending the data of array
if(getack_ee())
{
stop();
}
stop(); // stop condition for i2c communication
}
void Registers_read(void)
{
int i;
EEPROM_DIR |= 0x0E;//0X07;
TI_CC_Wait(35);
for (i=0;i<10;i++)
{
eeprom_r_byte(i,&ruart_buffer[i]);
TI_CC_Wait(35);
}
TI_CC_Wait(35);
}
void eeprom_r_byte(unsigned char add,unsigned char *buffer)
{
start(); // starting the i2c communication
sendb(0xA0); // sending the address of the device
if(getack_ee())
{
stop();
}
sendb(add); //sending the higher byte of the address word
if(getack_ee())
{
stop();
}
start(); // starting the i2c communication
sendb(0xA1); // sending the data of array
if(getack_ee())
{
stop();
}
*buffer = read(); // reading a byte from eeprom
putack_i2c(0);
stop(); // stop condition for i2c communication
}
void putack_i2c(unsigned char ack)
{
if(ack==0)
{
EEPROM_DIR |=SDA_EEPROM;
EEPROM_OUT&=~SDA_EEPROM; //SDA=0;
TI_CC_Wait(10);
}
else
{
EEPROM_DIR |=SDA_EEPROM;
EEPROM_OUT |=SDA_EEPROM; //SDA=1
TI_CC_Wait(10);
}
EEPROM_DIR |=SCL_EEPROM;
EEPROM_OUT |=SCL_EEPROM; // SCL=1;
TI_CC_Wait(10);
EEPROM_DIR |=SCL_EEPROM;
EEPROM_OUT&=~SCL_EEPROM; //SCL=0;
TI_CC_Wait(10);
}
/***************************************************************************************/