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

I can't enable Slave Select pin on 16F1508[SOLVED]

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



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

I can't enable Slave Select pin on 16F1508[SOLVED]
PostPosted: Sat May 09, 2015 1:03 pm     Reply with quote

Hello everyone.
I am trying to run SPI interface on 16F1508 but I have problem with the hardware SS(Slave Select) pin of the SPI. Scoped the signals on SCLK SDO are fine but SS (PIN_C6) isn't moving at all. I tried many different configurations but no success at the end. Here is the code:
Code:

#include <16F1508.h>
#FUSES INTRC_IO, NOWDT, PUT, NOMCLR, NOPROTECT, NOBROWNOUT, NOCLKOUT, NOIESO, NOFCMEN, NOWRT, NOLPBOR, NODEBUG, NOLVP
#USE delay(internal = 16M)
#use spi(FORCE_HW, BITS=8, ENABLE=PIN_C6, ENABLE_ACTIVE=0)
#include "NRF24L01.c"

void main()
{
   
setup_oscillator(OSC_16MHZ);
setup_spi(SPI_MASTER | SPI_SCK_IDLE_LOW | SPI_XMIT_L_TO_H | SPI_SS_C6);
   while(TRUE)
   {
      spi_write(0xAA);
      delay_us(100);
   } 
}

Any help would be much appreciated!
_________________
A person who never made a mistake never tried anything new.


Last edited by rikotech8 on Mon May 11, 2015 6:23 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 09, 2015 2:16 pm     Reply with quote

It's an input pin on a hardware SPI slave. The hardware master doesn't
use it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sat May 09, 2015 2:16 pm     Reply with quote

You need to use spi_xfer, not spi_write.

There are two _separate_ ways of driving the SPI with CCS. Spi_read and spi_write are for use with the old setup_spi method, and only gives simple operation (no slave select). For #use spi, you must use spi_xfer, which can then control the select line.

If you look at the manual, you will find that setup_spi refers you to spi_read and spi_write, while #use spi refers you to spi_xfer.

You must not mix the two methods.

#use spi, can control the pin as an output for the master device.

Get rid of the setup_spi line, and use spi_xfer to send, and the code can then control this line.

On the master device, the output, can be any pin (doesn't have to be the slave select pin).
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Sun May 10, 2015 2:58 am     Reply with quote

Thank you guys for replies.

Quote:
Get rid of the setup_spi line

Yes it works that way, but the BAUD rate is quite slower when I am not using this line, and I can't figure out why.

With this configuration:
Code:

#include <16F1508.h>
#FUSES INTRC_IO, NOWDT, PUT, NOMCLR, NOPROTECT, NOBROWNOUT, NOCLKOUT, NOIESO, NOFCMEN, NOWRT, NOLPBOR, NODEBUG, NOLVP
#USE delay(internal = 16M)
#use spi(FORCE_HW, BITS=8, ENABLE=PIN_C6, ENABLE_ACTIVE=0)
#include "NRF24L01.c"

void main()
{
   
   setup_oscillator(OSC_16MHZ);
   while(TRUE)
   {
      spi_xfer(0xAA);
      delay_us(10);
   } 
}

I send one byte for 25uS.

But when I use the setup_spi line in my code I get faster bit rate:


Code:

#include <16F1508.h>
#FUSES INTRC_IO, NOWDT, PUT, NOMCLR, NOPROTECT, NOBROWNOUT, NOCLKOUT, NOIESO, NOFCMEN, NOWRT, NOLPBOR, NODEBUG, NOLVP
#USE delay(internal = 16M)
#use spi(FORCE_HW, BITS=8, ENABLE=PIN_C6, ENABLE_ACTIVE=0)
#include "NRF24L01.c"

void main()
{
   
   setup_oscillator(OSC_16MHZ);
   setup_spi(SPI_MASTER | SPI_SCK_IDLE_LOW | SPI_XMIT_L_TO_H | SPI_SS_C6);
   while(TRUE)
   {
      spi_xfer(0xAA);
      delay_us(10);
   } 
}

Now I send one byte for approximately 2uS.

Much faster with second piece of code. Could you please shed some light.
_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sun May 10, 2015 6:48 am     Reply with quote

#use spi, allows you to specify the baud....
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Sun May 10, 2015 7:18 am     Reply with quote

Quote:
BAUD=n
Target bits per second, default is as fast as possible.

_________________
A person who never made a mistake never tried anything new.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sun May 10, 2015 12:21 pm     Reply with quote

If you believe that, you will believe anything..... Smile

You'll find it does go as fast as possible for software SPI, but for hardware, unless you specify the rate, it doesn't configure things like the prescaler.
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PostPosted: Sun May 10, 2015 1:23 pm     Reply with quote

Thx a lot T
_________________
A person who never made a mistake never tried anything new.
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