View previous topic :: View next topic |
Author |
Message |
Ringo42
Joined: 07 May 2004 Posts: 263
|
9356SPI using other pins |
Posted: Tue Dec 14, 2010 8:50 am |
|
|
I'm trying to use the 9356SPI code but I'm not using the standard SPI pins. How do I configure it?
I thought the line below would do it.
#use spi(DI=EEPROM_DI,DO=EEPROM_DO,CLK=EEPROM_CLK,MODE=2,BITS=8,BAUD=400000)
All I read back is -1, even if I write something different.
Here is all the code in my modified 9356SPI.c
Code: |
#define EEPROM_SELECT PIN_B2
#define EEPROM_DI PIN_B0
#define EEPROM_DO PIN_D7
#define EEPROM_CLK PIN_B1
#define EEPROM_ADDRESS BYTE
#define EEPROM_SIZE 256
#use spi(DI=EEPROM_DI,DO=EEPROM_DO,CLK=EEPROM_CLK,MODE=2,BITS=8,BAUD=400000)
void init_ext_eeprom() {
int1 i;
output_low(EEPROM_DI);
output_low(EEPROM_CLK);
output_low(EEPROM_SELECT);
i=input(EEPROM_DO);
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);
output_high(EEPROM_SELECT);
spi_write(0x9);
spi_write(0x80);
output_low(EEPROM_SELECT);
}
void write_ext_eeprom(EEPROM_ADDRESS address, BYTE data) {
output_high(EEPROM_SELECT);
spi_write(0xa);
spi_write(address);
spi_write(data);
output_low(EEPROM_SELECT);
delay_ms(11);
}
BYTE read_ext_eeprom(EEPROM_ADDRESS address) {
BYTE data;
output_high(EEPROM_SELECT);
spi_write(0x18);
spi_write(address);
data=spi_read(0);
output_low(EEPROM_SELECT);
return(data);
}
|
_________________ Ringo Davis |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Dec 14, 2010 9:01 am |
|
|
Here is the main code
Code: | #include <18f4520.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#include "9356spi_vario.c"
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
int value,address;
init_ext_eeprom();
for(address=0;address<255;address++)
{
WRITE_EXT_EEPROM( Address, address/2 );
value=READ_EXT_EEPROM( address ) ;
printf("address %d = %d\r\n",address,value);
}
} |
_________________ Ringo Davis |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Dec 14, 2010 9:48 am |
|
|
OK I found the 9356.c code that lets you setup your own pins, so that answers that question, but I still get back only -1's.
Looking at the Data sheet here
http://ww1.microchip.com/downloads/en/DeviceDoc/21794F.pdf
I don't understand the code. I'm using the 93C56B. Maybe that is the problem. The B is a 16 bit part.
Is there something I need to modify for the B part?
Ringo _________________ Ringo Davis |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Tue Dec 14, 2010 11:40 am |
|
|
Do you have the proper pullup resistors on the I/O lines, if required? |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Dec 14, 2010 12:09 pm |
|
|
Since the pins on the pic are treated as regular IO, they are driven high and low so there should not be a need for pullups.
Ringo _________________ Ringo Davis |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Dec 14, 2010 1:49 pm |
|
|
Perfect, Thanks. _________________ Ringo Davis |
|
|
|