View previous topic :: View next topic |
Author |
Message |
picramrom
Joined: 28 Dec 2006 Posts: 4
|
PIC18F4620 spi problem |
Posted: Thu Dec 28, 2006 2:09 am |
|
|
i used PIC18F452 in my circuit, but program memory is not sufficient any more. i thought i could use PIC18F4620 instead of PIC18F452. But spi_read is not working. please help me |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 28, 2006 2:47 am |
|
|
1. Post your compiler version.
2. Post your code to setup the spi module.
3. Post the code to do the spi read. |
|
|
picramrom
Joined: 28 Dec 2006 Posts: 4
|
|
Posted: Thu Dec 28, 2006 3:31 am |
|
|
compiler version 4.013
my souce code is that,
/////
setup_spi(spi_master | spi_l_to_h | spi_clk_div_16 );
ckp=1; //Data transmitted on rising edge of SCK
cke=0; wcol=0; sspov=0;
ds1306cs=0; //deselect rtc
db161rst=1; //wake up at45db161
db161cs=1; //deselect at45db161
delay_us(10);
e=253<<2; //page 253
e1=make8(e,1);
e0=make8(e,0);
db161cs=0;//select at45db161
spi_write(0x55); //page to buffer transfer
spi_write(e1);
spi_write(e0);
spi_write(0);
db161cs=1;
while(!db161rdy) {}//wait until at45db161 is ready
db161cs=1;
delay_us(10);
db161cs=0;
spi_write(0x56); //
spi_write(0);
spi_write(0);
spi_write(0);
spi_write(0);
for (i=0; i<20; i++) {serial[i]=spi_read();}
ds1306cs=0;//deselect rtc
db161cs=1;//deselect at45db161
db161rst=0;//reset at45db161
//////
at45db161 is a flash memory
ds1306 and at45db161 use same spi pins to communicate pic
these codes are running for PIC18F452, but when i use PIC18F4620, i can write data to the flash, but i can not read. |
|
|
Ttelmah Guest
|
|
Posted: Thu Dec 28, 2006 4:54 am |
|
|
Repeat after me:
If a program does not work with a V4 compiler, try 3.249...
The V4 compilers are just starting to produce some useable code, but to anyone writing code that they want to work, the last useable compiler was 3.249...
Second. Use the 'code' button when posting code.
Now you use a 'fiddly' way of setting up the SPI. Using half of the CCS function, and then going DIY for the rest, and setting CKE/CKP/WCOL/SSPOV yourself. This is somewhat 'messy', and you will need to triple check that th bit definitions are correct for the latter part.
You don't show how you configure the SSP speed. Look at the errata sheet for the chip. Notice the timing peculiarity when running as master with a relatively slow clock. Could this apply?...
Best Wishes |
|
|
picramrom
Joined: 28 Dec 2006 Posts: 4
|
|
Posted: Thu Dec 28, 2006 5:44 am |
|
|
thank you for advice,
i wrote first comment in ccs forum, because of that i made copy-paste my code.
i don't write "wcol=0; sspov=0;" in my PIC18F452 source code, but "ckp=1; cke=0;" is necessary for regularly working.
i tried all ways to solve this problem, For example i added "wcol=0; sspov=0;". and i tried to make slow ssp speed, but it is not working.
the other strange thing i can read data from rtc(DS1306).
My circuit works at 40 MHz.
i tried 3.245 version, but it is not working.
i am going to try 3.249, i hope i can solve.
the most important thing that why does PIC18F452 work and doesn't PIC18F4620 work? is there any logical explanation for this?
Regards |
|
|
picramrom
Joined: 28 Dec 2006 Posts: 4
|
|
Posted: Thu Dec 28, 2006 5:50 am |
|
|
i tried 3.249 version, but it is not working. |
|
|
Ttelmah Guest
|
|
Posted: Thu Dec 28, 2006 6:06 am |
|
|
The CKP bit, will be set high, if you use SPI_H_TO_L. You are turning the bit off in the CCS setup, and then setting it manually. Get the CCS setup right...
CKE is already set low in the CCS setup (this is set high by SPI_XMIT_L_TO_H, if required).
SSPOV, can never be set in a master device.
Have you looked at the errata I mentioned?. This could be the whole problem.
Best Wishes |
|
|
|