Jump to content

Recommended Posts

Does anyone know where I can get a good spi library or at leaste where to start with building a library? I have a PIC 16F88 and it does support hardware SPI but since I have moved to this compiler I have been unable to find one. My only other option is using software spi but the compiler seems to be having an issue with uns8 which i think is a data type that is used. Any help would be great.

Share this post


Link to post
Share on other sites
Does anyone know where I can get a good spi library or at leaste where to start with building a library? I have a PIC 16F88 and it does support hardware SPI but since I have moved to this compiler I have been unable to find one. My only other option is using software spi but the compiler seems to be having an issue with uns8 which i think is a data type that is used. Any help would be great.

 

Hi Steven,

 

I haven't used the hardware SPI function, but you can find software SPI libraries here: Embedded Adventures.

 

uns8 is normally #defined as unsigned char or similar - you can find such defines in the pic_utils.h from the website - eg:

#define int8  char
#define uns8  unsigned char
#define uns16 unsigned int
#define int16 int
#define uns32 unsigned long
#define int32 long

 

cheers

Ian.

Share this post


Link to post
Share on other sites

All you have to do to use the hardware SPI module is set up the registers on pages 88 and 89 on the data sheet. Note that most of the bits are read-only and used only for I2C, so those can be ignored.

 

In master mode:

That's it. To send/receive data (both are done simultaneously with SPI), simply write the byte you want to send to sspbuf. From there you can either poll SSPIF or enable the respective interrupt. Once SSPIF is set or the interrupt is triggered, read the value in sspbuf to obtain the byte that was received.

 

Slave mode isn't much more complicated, but since you are looking for a library, I'm assuming you want to use master mode to read/write to some EEPROM, RAM, port extender, or something of that nature.

 

This address has a good overview of the SPI module in a PICmicro:

ww1.microchip.com/downloads/en/devicedoc/spi.pdf

 

 

- Bill

Share this post


Link to post
Share on other sites

Thanks for the help. I think im going to attempt software SPI until i can figure out how to correctly setup the hardware spi as it is more efficient to use the hardware SPI. I have looked at different examples and most have a basic structure of a for loop and switching the right pins at the correct time. I was told that you have to read the data after the send even if your not going to do anything with it but from what I can tell the software SPI does not do this or at leaste im not seeing where it reads in the data. Also most statements take a variable say inputdata.7 im not sure exactly what this does?

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...