|
|
View previous topic :: View next topic |
Author |
Message |
epideath
Joined: 07 Jun 2006 Posts: 47
|
SPI to 25L640 woes :-( |
Posted: Fri Jun 09, 2006 10:29 pm |
|
|
(using a 18F4520)
OK having a really tough time trying to communicate to a 25L640 EEPROM. My board electronics all work because I can reload the MCC18 code that I have and it reads and writes to the EEPROM with no problems.
I can't seem to get the PIC to even read one address (zero) from the EEPROM. I alos have a write function. but it doesn't seem to work either. I have written a known value to adress zero it is a 1. but after a read it alwyas comes back with zero. Also tried writing a value then read it with my MCC18 program and I can see that it hasn't changed the value. It is the same as that orignally written by the MCC18 program.
I have tried the 25640.c code in the device folder. That doesn't seem to work either. and that doesn't even use the SPI but just drives the I/O directly.
I'm sure that it is something setting wise that i'm over looking. As I'm new to CCS PICC.
Here is the code that I have in CCS PIC-C. Ported from MCC18 that code is below this current code.
I have tried not playing with the SKE and SSPEN. just using the setup_spi. but that doesn't seem to matter one way or the other.
Oh and EditStep.StepType is defined as int8
Hope this makes some sense.
Any pointers or thoughts would be great.
Thanks
Code: |
SET_TRIS_C(0x10); //00010000 All output except C4
|
Code: |
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4);
SSPEN = 0;
SMP = 1;
CKE = 1;
SSPEN = 1;
|
Code: |
void Poll_EE(void)
{
int8 st;
do
{
output_low(PIN_C2);
spi_write(RDSR);
st = spi_read();
output_high(PIN_C2);
}while(st & 0x01);
}
void LoadStepFromEE(int8 program, int8 step)
{
int16 address;
int8 lsb, msb;
char str[4];
output_high(PIN_C2);
address = (int16) program * MAX_STEPS * STEP_SIZE;
address += (int16)(step-1) * STEP_SIZE;
lsb = address & 0xFF;
msb = address >> 8;
Poll_EE();
output_low(PIN_C2);
spi_write(READ_SPI);
spi_write(0);
spi_write(0);
EditStep.StepType = spi_read();
output_high(PIN_C2);
}
|
[Here is the MCC18 code that I'm trying to port from.
Code: |
void busy_polling (void)
{
char var;
do
{
PORTCbits.RC2 = 0; //assert chip select
var = putcSPI(SPI_RDSR); //send read status command
var = getcSPI(); //read data byte
PORTCbits.RC2 = 1; //negate chip select
} while (var & 0x01); //stay in loop until !busy
}
void LoadStepFromEE(char program, char step)
{
unsigned int address;
unsigned char address_low, address_high;
PORTCbits.RC2 = 1;
//Calculate address high and address low of program/step
address = (int)(program) * MAX_STEPS * STEP_SIZE;
address = address + (int)(step-1) * STEP_SIZE;
address_low = (unsigned char) address & 0xFF;
address_high = (unsigned char) (address >> 8) & 0xFF;
OpenSPI(SPI_FOSC_4, MODE_00, SMPEND);
busy_polling();
PORTCbits.RC2 = 0;
putcSPI(SPI_READ);
putcSPI(address_high); //Address High
putcSPI(address_low); //Address Low
//Read Step Data
Step.StepType = getcSPI();
CloseSPI();
PORTCbits.RC2 = 1;
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 09, 2006 11:24 pm |
|
|
See the following thread, which shows how to use the CCS 25640.C
driver. It's possible that you couldn't make it work because you were
using the wrong pins. The example shows how to use different pins
than the ones defined in the CCS driver file.
http://www.ccsinfo.com/forum/viewtopic.php?t=26212
Also, you should be aware that the following line doesn't generate
an SPI clock:
To generate a clock (from master PIC to slave eeprom), then do this:
Note the zero parameter. This is in the manual. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|