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

Software SPI help !!!
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aka211



Joined: 24 May 2010
Posts: 15

View user's profile Send private message

Software SPI help !!!
PostPosted: Thu Jun 10, 2010 8:06 pm     Reply with quote

I want to use software SPI, but I still have something not clear.
In the syntax #use spi(),
I've read that DI=pin " Optional pin for incoming data" so it's the data input pin but that's master data input or slave data input?
I wonder if DI pin have the same function as SDI in hardware SPI module ? or DI ~SDO ?

Anyone help me, plz !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 11, 2010 12:46 pm     Reply with quote

Quote:

I've read that DI=pin " Optional pin for incoming data" so it's the data
input pin but that's master data input or slave data input?

"DI" would be the input pin, for either Master or Slave. If it's configured
as a Master, DI is input. If it's configured as a Slave, DI is also the input.
But, software SPI should only be used for the Master. If you want to do
an SPI slave, then use the hardware module (SSP or MSSP). There are
dedicated pins on the PIC for the hardware SPI module.


Quote:
I wonder if DI pin have the same function as SDI in hardware SPI module ?

Yes, that's right. "DI" is the same as "SDI".
aka211



Joined: 24 May 2010
Posts: 15

View user's profile Send private message

PostPosted: Sun Jun 13, 2010 9:18 pm     Reply with quote

Thanks alot PCM !
So, if I config the pic16f946 as master use software SPI and a slave eeprom.
The DI pin of the PIC should be connected to SDO pin of the eeprom, right?


Like the picture above, RG1 will be DI pin?


Last edited by aka211 on Mon Jun 14, 2010 3:01 am; edited 4 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 13, 2010 10:24 pm     Reply with quote

I can't view your image, but yes, the DI pin on the PIC goes to the SDO
pin on the eeprom.
nahumof



Joined: 09 Apr 2011
Posts: 15

View user's profile Send private message

spi slave
PostPosted: Sat Apr 09, 2011 10:09 am     Reply with quote

hi all
I'm intending to do some communication between 2 pics by software spi
so
Quote:
software SPI should only be used for the Master

then what is the use of #use spi(slave.......)? doesn't work as slave?

Does anybody have some code for an slave spi using software spi?
I was trying to do this
Code:

#int_ssp
void ssp_isr(void)
{
buffer[next_in] = spi_xfer();

next_in++;

if(next_in >= BUFFER_SIZE)
   next_in = 0;

}

At the slave with no results and I found this post:cry:
I guess it only work with spi_read();

regards
nahum Rolling Eyes
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 09, 2011 1:19 pm     Reply with quote

if you don't get anywhere using SPI....
...you might consider just using the serial interface(aka RS232) for inter PIC communications.Fewer 'startup' headaches, easy to code,just as fast,examples in the examples folder.....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 09, 2011 2:22 pm     Reply with quote

Quote:
I'm intending to do some communication between 2 pics by software spi

Why ? Does your slave PIC not have an SSP module ?

Post the part numbers of your master and slave PICs.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Apr 09, 2011 2:26 pm     Reply with quote

One of them he is using has hardware (16F946 stated earlier).
_________________
Google and Forum Search are some of your best tools!!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 09, 2011 2:34 pm     Reply with quote

Right, but there are two people on this thread. The first one is aka211
and the 2nd one is nahumof. aka211 is the one with the 16F946.
We don't know what nahumof is using.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Apr 09, 2011 2:40 pm     Reply with quote

Good point, I missed that... Switching posters in mid thread has caught me a few times.
_________________
Google and Forum Search are some of your best tools!!!!
nahumof



Joined: 09 Apr 2011
Posts: 15

View user's profile Send private message

PostPosted: Sat Apr 09, 2011 3:34 pm     Reply with quote

ok tks for the reply

I'm using 18f4550 as master using software SPI works fine, and 16f876 as slave spi also sw fail.

I can't use hardware spi because its being used by another purpose in a already build pcb.

And I found this code for software spi but I want to use #use_spi or interrupt by ssp.

Code from Ttelmah
Code:

void send_spi_byte(int8 ClockPin, int8 DataOutPin,int8 val_to_send) {
   int8 count;
   for (count=0;count<8;count++) {
      output_bit(DataOutPin, shift_left(&val_to_send,1,0));
      output_high(ClockPin);
      output_low(ClockPin);
   }
}

int8 get_spi_byte(int8 ClockPin, int8 DataInPin) {
   int8 count;
   int8 val;
   for (count=0;count<8;count++) {
      output_high(ClockPin);
      shift_left(&val,1,input(DataInPin));
      output_low(ClockPin);
   }
   return(val);
}


I could use #use_spi as pic slave?
tks Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 09, 2011 4:10 pm     Reply with quote

The code you posted is for a software SPI master, not a slave. That code
generates the clock, and slaves don't make a clock. Only the master does
it. And, the code doesn't try to find the clock edge. A software slave must
do that, either by polling, or by triggering an interrupt on the clock edge.

And, #int_ssp is used only by a hardware SPI slave. But you said
you don't have the SPI hardware available.

With regard to #use spi() for a slave, here is a thread where I go through
it in detail. I noted that some bugs existed in the compiler version
available at that time. I haven't looked at it lately. It's possible that CCS
may have fixed it by now. What's your version ? My guess is, probably
4.093, etc. So it probably has bugs.
https://www.ccsinfo.com/forum/viewtopic.php?t=40421

------------------
Edit: Fixed link to point to correct thread.


Last edited by PCM programmer on Sat Apr 09, 2011 5:17 pm; edited 1 time in total
nahumof



Joined: 09 Apr 2011
Posts: 15

View user's profile Send private message

PostPosted: Sat Apr 09, 2011 4:46 pm     Reply with quote

Yes of course I see that is master spi code
Quote:
slaves don't make a clock

I was meaning apply something like that for polling using ssp interrupt but now I'm aware
Quote:
only by a hardware SPI slave
so maybe the options is try polling with if cycles!!! Shocked
yes my ccs version is 4.093

It seems I'm stuck Crying or Very sad its also strange that anyone out there haven't try to make slave spi using software (different pin assignment).

Apologies for my bad english.

tks for all PCM I will try to make it work Smile
nahumof



Joined: 09 Apr 2011
Posts: 15

View user's profile Send private message

PostPosted: Sat Apr 09, 2011 5:27 pm     Reply with quote

tx for fix the link Very Happy
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Apr 09, 2011 8:26 pm     Reply with quote

nahumof wrote:
It seems I'm stuck Crying or Very sad its also strange that anyone out there haven't try to make slave spi using software (different pin assignment).
A SPI master in software is easy, but a SPI slave in software is a lot more work. That's why you find few examples.

Going back to the basics. Why do you want to use SPI and not use the UART as suggested earlier in this thread?

Do you have any pin available that can trigger an hardware interrupt in the slave?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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