CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

9356SPI using other pins

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

9356SPI using other pins
PostPosted: Tue Dec 14, 2010 8:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 14, 2010 9:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 14, 2010 9:48 am     Reply with quote

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: 9245
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 14, 2010 11:40 am     Reply with quote

Do you have the proper pullup resistors on the I/O lines, if required?
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Tue Dec 14, 2010 12:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 14, 2010 1:27 pm     Reply with quote

This thread has a software SPI driver for the 93LC56B which can use
any i/o pins:
http://www.ccsinfo.com/forum/viewtopic.php?t=38064
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Tue Dec 14, 2010 1:49 pm     Reply with quote

Perfect, Thanks.
_________________
Ringo Davis
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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