[SOLVED] pic18f problem with eeprom

Status
Not open for further replies.

amit deulkar

Junior Member level 1
Joined
May 25, 2012
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,537
hi iam using pic18f452
in my project i am interfacing gsm modem with mcu. In that i am writing and reading some data from eeprom.but problems come when i am writing data to eeprom after that i am not getting response from modem i enable all global interrupt,receive interrupt after writing. please anybody help.
 

after u write u gotta provide some delay before u enable interrupts again .
if using mikroc consider this an example .

char MODE_TIME[]={0,0,0}

void EEPROM_upload_()
{ char data_write=0;
for(data_write=0;data_write<=2;data_write++)

{
switch(data_write+1)
{
case 1:EEPROM_Write(base_add_EEPROM+data_write,MODE_TIME[0]);
break;
case 2:EEPROM_Write(base_add_EEPROM+data_write,MODE_TIME[1]);
break;
case 3:EEPROM_Write(base_add_EEPROM+data_write,MODE_TIME[2]);
break;
default:break;
}
Delay_ms(20);
}

}



void main()
{
while(1)
{

if(STORE_SSG) //STORE_SSG is enabled using a timer /
{

EEPROM_upload_();
INTCON.GIE=1;
STORE_SSG=0;
}

}

}
 


thanks for the reply i will check that
 

i check what you suggest but it is still not working can you please help can i show you my code
 

Post your code.

here is my code
/*
* File: sms_read_pot.c
* Author: Free User
*
* Created on December 3, 2012, 10:45 AM
*/
#include <stdio.h>
#include <stdlib.h>
#include<p18f452.h>
#include<string.h>
#include<EEP.h>

#pragma config OSC = HS
#pragma config BORV=45, PWRT=ON,BOR=ON
#pragma config WDT =OFF

void uart_init(void);
void delay(unsigned char);
void SerialTx(char);
void modem_init(void);
void Delay_10Sec(void);
void msg_read(void);
void send_msg(void);
void flush_buffer(void);
void send_msg(void);
unsigned char check(void);
void write_no(unsigned char);
void get_service_provider(void);
unsigned char ee_read (unsigned char);
void ee_write(unsigned char,unsigned char );
void eeprom_write(void);
unsigned char SERVICE[11];
char new_msg=0,msg_flag,RES_PH_N0[15];
char buffer[100],msg[12],TICK=0;

#pragma interrupt chk_int
void chk_int(void) //interrupt check loop
{
if(PIR1bits.RCIF==1)
msg_read();
}

#pragma code high_prt =0x08
void high_prt(void)
{
_asm
GOTO chk_int
_endasm
}
#pragma code
void main(void)
{
unsigned char count=0,i=0,pos,j;
unsigned char QSPN[]="AT+QSPN?";
unsigned char ATE0[] = "ATE0";
uart_init();
Delay_10Sec();
Delay_10Sec();
eeprom_write();
PIE1bits.RCIE=1;
Delay_10Sec();
Delay_10Sec();
for(count=0;ATE0[count]!='\0';count++)
SerialTx(ATE0[count]);
SerialTx(0X0D);
SerialTx(0X0A);
Delay_10Sec();
Delay_10Sec();
for(count=0;QSPN[count]!='\0';count++)
SerialTx(QSPN[count]);
SerialTx(0X0D);
SerialTx(0X0A);
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
get_service_provider();
modem_init();
TRISB = 0x7F;
PORTBbits.RB7 = 0;

while(1)
{
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
for(i=0;i<=100;i++)
SerialTx( buffer);

send_msg();
i=0;
pos=0;
if(new_msg==1)
{
new_msg=0;
while(buffer[pos]!='+')
pos++;
pos++;
if(buffer[pos]=='C' && buffer[pos+1]=='M' && buffer[pos+2]=='T')
{
//PORTBbits.RB7 = 1;
while(buffer[pos]!= '"')
pos++;
pos++;
pos++;
pos++;
pos++;
i=0;
for(i=0;i<10;i++,pos++)
RES_PH_N0=buffer[pos];

for(i=0;i<10;i++)
SerialTx( RES_PH_N0);
while(buffer[pos]!= '#')
pos++;
i=0;
pos++;
j=0;
while(buffer[pos]!= '#')
{
msg=buffer[pos];
i++;
pos++;
j++;
}
for(i=0;i<=j;i++)
SerialTx( msg);
i=0;
while(j!=0)
{
if(msg=='O'&& msg[i+1]=='N')
PORTBbits.RB7 = 1;
if(msg=='O'&& msg[i+1]=='F' && msg[i+2]=='F')
PORTBbits.RB7 = 0;
if(msg=='N' && msg[i+1]=='U'&& msg[i+2]=='M'&& msg[i+3]=='1')
write_no(1); //problem area
if(msg=='N'&& msg[i+1]=='U'&& msg[i+2]=='M'&& msg[i+3]=='2')
write_no(2);
j--;
i++;
}
//new_msg=0;

}
}
// new_msg=0;
flush_buffer();
for(count=0;count<20;count++)
{
RES_PH_N0[count]=0;
msg[count]=0;
}
TICK=0;
}
}
//+CMT: "+919657034584","Pankaj","12/12/03,15:10:06+22" #hi#
void uart_init(void)
{
TRISCbits.TRISC6=0; // tx pin as o/p
TRISCbits.TRISC7=1; // rx pin as i/p
SPBRG=17; // (172800/9600) FOR 9600 BAUD RATE
RCSTAbits.SPEN=1;
RCSTAbits.CREN=1;
TXSTA=0X20; // TRANSMIT ENABLE
TXSTAbits.TXEN=1;
RCSTA=0X90;
PIR1bits.RCIF=0;
INTCONbits.PEIE=1;
PIE1bits.RCIE=0;
INTCONbits.GIE=1;
}
void modem_init(void)
{
unsigned char AT[] = "AT";
unsigned char CMGF[]="AT+CMGF=1";
unsigned char CSCA[]="AT+CSCA=";
unsigned char CNMI[]="AT+CNMI=2,2,0,0,0";
unsigned char CSAS[]="AT+CSAS";
unsigned char count;
for(count=0;AT[count]!='\0';count++)
SerialTx(AT[count]);
SerialTx(0X0D);
SerialTx(0X0A);
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
for(count=0;CMGF[count]!='\0';count++)
SerialTx(CMGF[count]);
SerialTx(0X0D);
SerialTx(0X0A);
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
for(count=0;CSCA[count]!='\0';count++)
SerialTx(CSCA[count]);
SerialTx('"');
SerialTx('+');
SerialTx('9');
SerialTx('1');
for(count=0;count<10;count++)
SerialTx(SERVICE[count]);
SerialTx('"');
SerialTx(0X0D);
SerialTx(0X0A);
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
for(count=0;CNMI[count]!='\0';count++)
SerialTx(CNMI[count]);
SerialTx(0X0D);
SerialTx(0X0A);
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
for(count=0;CSAS[count]!='\0';count++)
SerialTx(CSAS[count]);
SerialTx(0X0D);
SerialTx(0X0A);
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
}

void msg_read(void)
{
unsigned char res_char;
PIE1bits.RCIE=0; //disable receive interrupt
res_char=RCREG;
buffer[TICK]=res_char;
if(res_char=='+')
new_msg=1;
TICK++;
PIE1bits.RCIE=1; //enable receive enable
}
void Delay_10Sec(void)
{
unsigned char count;
TMR1H=0X26;
TMR1L=0XFD;
for(count=0;count<=60;count++)
{
T1CONbits.TMR1ON=1;
while(PIR1bits.TMR1IF==0);
TMR1H=0X26;
TMR1L=0XFD;
PIR1bits.TMR1IF=0;
T1CONbits.TMR1ON=0;
}
}

void delay(unsigned char count)
{
char i,j ;
for(i=0;i<=1;i++)
for(j=0;j<count;j++);
}
void SerialTx(char cmd)
{
TXREG= cmd;
delay(1);
while(PIR1bits.TXIF==0);
}


void flush_buffer(void)
{
unsigned char count;
for(count=0;count<80;count++)
buffer[count]=0;
}
void write_no(unsigned char no)
{
unsigned char count,addr;
if(no==1)
{
addr=70;
for(count=0;count<10;count++,addr++)
Write_b_eep(addr,RES_PH_N0[count]);
INTCONbits.GIE=1;
PIE1bits.RCIE=1;

// ee_write(addr,RES_PH_N0[count]);
}
if(no==2)
{
addr=81;
for(count=0;count<10;count++,addr++)
Write_b_eep(addr,RES_PH_N0[count]);
//ee_write(addr,RES_PH_N0[count]);
INTCONbits.GIE=1;
PIE1bits.RCIE=1;
}

}
void send_msg(void)
{
unsigned char CMGS[]="AT+CMGS=";
unsigned char addr,count,read_data;
// PIE1bits.RCIE=0;
for(count=0;CMGS[count]!='\0';count++)
SerialTx(CMGS[count]);
SerialTx('"');
SerialTx('+');
SerialTx('9');
SerialTx('1');
addr=70;
for(count=0;count<10;count++,addr++)
{

// read_data=ee_read(addr);
read_data=Read_b_eep(addr);
delay(10);
SerialTx(read_data);
}
SerialTx('"');
SerialTx(0X0D);
SerialTx(0X0A);
SerialTx('h');
SerialTx('i');
SerialTx(0X1A);
delay(50);
for(count=0;CMGS[count]!='\0';count++)
SerialTx(CMGS[count]);
SerialTx('"');
SerialTx('+');
SerialTx('9');
SerialTx('1');
addr=81;
for(count=0;count<10;count++,addr++)
{

// read_data=ee_read(addr);
read_data=Read_b_eep(addr);
delay(10);
SerialTx(read_data);
}
SerialTx('"');
SerialTx(0X0D);
SerialTx(0X0A);
SerialTx('h');
SerialTx('i');
SerialTx(0X1A);
delay(50);
//PIE1bits.RCIE=1;*/
}
void eeprom_write(void)
{
unsigned char airtel[11]="9890051914";
unsigned char docomo[11]="9037442369";
unsigned char idea[11]="9822078000";
unsigned char vodafone[11]="9823000040";
unsigned char count,addr=0;
for(count=0;count<10;count++,addr++)
ee_write(addr,airtel[count]);
delay(10);
addr=22;
for(count=0;count<10;count++,addr++)
ee_write(addr,docomo[count]);
delay(10);
addr=33;
for(count=0;count<10;count++,addr++)
ee_write(addr,idea[count]);
delay(10);
addr=55;
for(count=0;count<10;count++,addr++)
ee_write(addr,vodafone[count]);
delay(10);
}
void ee_write(unsigned char addr,unsigned char data)
{
EEADR=addr;
EEDATA=data;
EECON1bits.EEPGD=0; //point to eeprom
EECON1bits.CFGS=0; //access eeprom
EECON1bits.WREN=1; //allows to write
INTCONbits.GIE=0; //disable global interrupt
EECON2=0X55;
EECON2=0XAA;
EECON1bits.WR=1;
INTCONbits.GIE=1; //enable global interrupt
while(PIR2bits.EEIF==0);
PIR2bits.EEIF=0;
EECON1bits.WREN=0;
}
unsigned char ee_read (unsigned char addr)
{
EEADR=addr;
EECON1bits.EEPGD=0; //point to eeprom
EECON1bits.CFGS=0; //access eeprom
EECON1bits.RD=1; //enable read
delay(1);
return(EEDATA);
}
void get_service_provider(void)
{
unsigned char count,flag=0,addr,read_data,count1;
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
Delay_10Sec();
while(buffer[count]!='+')
count++;
count++;
if(buffer[count]=='Q' && buffer[count+1]=='S' && buffer[count+2]=='P')
{
PORTBbits.RB7 = 1;
while(buffer[count]!= '"')
count++;
count++;
if(buffer[count]=='A'&& buffer[count+1]=='I')
{
count1=0;
for(addr=0;addr<10;addr++,count1++)
{

read_data=ee_read(addr);
delay(10);
SERVICE[count1]=read_data;
}
}
if(buffer[count]=='B'&& buffer[count+1]=='S')
{
count1=0;
for(addr=11;addr<21;addr++,count1++)
{

read_data=ee_read(addr);
delay(10);
SERVICE[count1]=read_data;
}
}
if(buffer[count]=='T'&& buffer[count+1]=='A')
{
PORTBbits.RB7 = 0;
count1=0;
for(addr=22;addr<32;addr++,count1++)
{

read_data=ee_read(addr);
delay(10);
SERVICE[count1]=read_data;
}
}
if(buffer[count+1]=='D'|| buffer[count+2]=='E')
{
count1=0;
for(addr=33;addr<43;addr++,count1++)
{

read_data=ee_read(addr);
delay(10);
SERVICE[count1]=read_data;
}
}
if(buffer[count]=='R'&& buffer[count+1]=='E')
{
count1=0;
for(addr=44;addr<54;addr++,count1++)
{

read_data=ee_read(addr);
delay(10);
SERVICE[count1]=read_data;
}
}
if(buffer[count]=='V'&& buffer[count+1]=='o')
{
count1=0;
for(addr=55;addr<65;addr++,count1++)
{

read_data=ee_read(addr);
delay(10);
SERVICE[count1]=read_data;
}
}

}
new_msg=0;
}

in this code in initial part i am writing & reading from eeprom perfectly.But problem comes when i am trying to write information received from sms. I highlight that area as problem area
 

What is the problem you are facing? Do you want to write data to internal eeprom of PIC? Edit you last post and post your code between code tags. Press # button to get code tags. Also post the code part which is giving problem.

Is the problem only with write_no(1)? Is write_no(2) working properly?

Can you show the function definition of Write_b_eep()?
 
Last edited:


problem is with both write_no(1) & write_no(2)

if(new_msg==1)
{
new_msg=0;
while(buffer[pos]!='+')
pos++;
pos++;
if(buffer[pos]=='C' && buffer[pos+1]=='M' && buffer[pos+2]=='T')
{
//PORTBbits.RB7 = 1;
while(buffer[pos]!= '"')
pos++;
pos++;
pos++;
pos++;
pos++;
i=0;
for(i=0;i<10;i++,pos++)
RES_PH_N0=buffer[pos];

for(i=0;i<10;i++)
SerialTx( RES_PH_N0);
while(buffer[pos]!= '#')
pos++;
i=0;
pos++;
j=0;
while(buffer[pos]!= '#')
{
msg=buffer[pos];
i++;
pos++;
j++;
}
for(i=0;i<=j;i++)
SerialTx( msg);
i=0;
while(j!=0)
{
if(msg=='O'&& msg[i+1]=='N')
PORTBbits.RB7 = 1;
if(msg=='O'&& msg[i+1]=='F' && msg[i+2]=='F')
PORTBbits.RB7 = 0;
if(msg=='N' && msg[i+1]=='U'&& msg[i+2]=='M'&& msg[i+3]=='1')
write_no(1);
if(msg=='N'&& msg[i+1]=='U'&& msg[i+2]=='M'&& msg[i+3]=='2')
write_no(2);
j--;
i++;
}
//new_msg=0;

}
}
// new_msg=0;
flush_buffer();
for(count=0;count<20;count++)
{
RES_PH_N0[count]=0;
msg[count]=0;
}
TICK=0;
}

void write_no(unsigned char no)
{
unsigned char count,addr;
if(no==1)
{
addr=70;
for(count=0;count<10;count++,addr++)
Write_b_eep(addr,RES_PH_N0[count]);
INTCONbits.GIE=1;
PIE1bits.RCIE=1;

// ee_write(addr,RES_PH_N0[count]);
}
if(no==2)
{
addr=81;
for(count=0;count<10;count++,addr++)
Write_b_eep(addr,RES_PH_N0[count]);
//ee_write(addr,RES_PH_N0[count]);
INTCONbits.GIE=1;
PIE1bits.RCIE=1;
}

}
 

Try to write some data using Write_b_eep() function. Insert this statement Write_b_eep(0x11, 0x0D); in your code and then read the address 0x11 of eeprom using read eeprom function. Then if the read value is 0x0D then light a led. It will show whether the problem is with Write_b_eeprom() or some other part of the code.
 


actually my problem is not with eeprom read write but after write_no() function my receiving functions not working
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…