SPI EEPROM & dspic

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
humphrey
Posts: 2
Joined: 11 Sep 2009 09:35

SPI EEPROM & dspic

#1 Post by humphrey » 11 Sep 2009 09:47

Hi,
I want to read data contained in a (1Mbit) 25LC1024 to a dspic30f4013;
are there any examples already made?
thanx

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

#2 Post by anikolic » 15 Sep 2009 13:45

Hi,
I can only suggest you should try writing your own code using SPI or Soft_SPI libraries of our compiler. Do some research on your EEPROM by reading it's datasheet http://ww1.microchip.com/downloads/en/D ... 22064A.pdf. Give it a try, and ask for help if having trouble with code.

Best regards,
Aleksandar
Web Department Manager

khuenguyen
Posts: 8
Joined: 08 Sep 2009 04:30

#3 Post by khuenguyen » 24 Sep 2009 05:29

Hi guys!
Can you help me?
this is my code:
........................
char txt[7];
unsigned short p;
unsigned char Key=0;
unsigned long eeAddr;
int k;
//Tunr off ADC
ADPCFG = 0xFFFF;
//configure GLCD
Glcd_Config(&PORTB, 4, &PORTB,5, &PORTF,0,&PORTF, 1,&PORTF, 5, &PORTF, 4, &PORTB, &PORTD, 0);
Delay_100ms();
//Clear screen
Glcd_Fill(0x00);
Delay2S();
dodoc1=10;
eeAddr = 0x7FFC80;
Eeprom_Erase(eeAddr);
Delay_100ms();
Eeprom_Write(eeAddr,dodoc1);
Delay_100ms();
p = Eeprom_Read(eeAddr);
p=p+3;
Delay_100ms();
sprintf(txt, "dodoc1=%d", p);
Glcd_Set_Font(FontSystem5x8, 5, 8, 32);
Glcd_Write_Text(txt,64,1,1);

//configure PORTE to control GLCD
TRISE = 0xFFFF;
while(1)
{
Key=KeyScan();
switch(Key)
{
case NoKeyPressed: break;
//select
case Key1Pressed: break;
//UP/DOWN
case Key2Pressed: break;
//Enter
case Key3Pressed:
{
k=k+1;
Delay2S();
if(k==1)
{
Glcd_Fill(0x00);
p = Eeprom_Read(eeAddr);
Delay_100ms();
sprintf(txt, "dodoc1=%d", p);
Glcd_Set_Font(FontSystem5x8, 5, 8, 32);
Glcd_Write_Text(txt,64,1,1);
}
if(k==2)
{
}
break;
}
case Key4Pressed: break;
case Key5Pressed: break;
case Key6Pressed: break;
case Key7Pressed: break;
default: break;
}
}
............
}
The first, i want to store a value into EEPROM of Dspic30f4011. It's docdoc1. then, i want to display it at Graphic LCD.
if i press button 3 one time, then read dodoc1 again, then display it again, to check EEPROM.
Many my tests:
1) case 1:
i don't use dodoc1's variable, and i write a value: it's ten.
........
Eeprom_Write(eeAddr,10)
..........
result are:
dodoc1=13;
(Clear screen and delay)
dodoc1=10;
2) case 2:
i use dodoc1's variable.
dodoc1=10;
...
Eeprom_Write(eeAddr,dodoc1);
...
Result are:
dodoc1=13;
(Clear screen and delay)
dodoc1=-1; ( if don't have fuction: Delay_100ms()
...........
Glcd_Fill(0x00);
p = Eeprom_Read(eeAddr);
sprintf(txt, "dodoc1=%d", p);
Glcd_Set_Font(FontSystem5x8, 5, 8, 32);
Glcd_Write_Text(txt,64,1,1);)
...............
dodoc1=255; ( if have: Glcd_Fill(0x00);
Delay_100ms();
p = Eeprom_Read(eeAddr);
sprintf(txt, "dodoc1=%d", p);
Glcd_Set_Font(FontSystem5x8, 5, 8, 32);
Glcd_Write_Text(txt,64,1,1);)
..........
3) case 3: i don't use dodoc1's variable:
..............
Eeprom_Write(eeAddr,10);
.............
Glcd_Set_Font(FontSystem5x8, 5, 8, 32);
Glcd_Write_Text(txt,64,1,1);)
.................
Result are:
dodoc1=13;
(Clear screen and delay)
dodoc1=1G;
i don't know why?
Help me!
Thank so much!

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”