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

spi_xfer_in usage on PIC16F15325

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



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

spi_xfer_in usage on PIC16F15325
PostPosted: Sun Dec 22, 2019 5:20 am     Reply with quote

I would like to use the function spi_xfer_in for reading an external signal with its clock and the compilation says:
"*** Error 51 "CCS_15325_Micro.c" Line 23(27,28): A numeric expression must appear here"

Here is my code:
Code:
#include <CCS_15325_Micro.h>
#define LED PIN_A0
#define DELAY 10

#use spi (SLAVE, CLK=PIN_C0, DI=PIN_C1, MODE=0, BITS=24, STREAM=SPI_1)

unsigned long data_in;

#INT_EXT
void  EXT_isr(void) {
  output_toggle(PIN_A1);
}

void main() {
  enable_interrupts(INT_EXT);
  enable_interrupts(GLOBAL);
 
  while(TRUE) {
    //Example blinking LED program
    output_toggle(LED);
    delay_ms(DELAY);
    //TODO: User Code
    data_in = spi_xfer_in();
  }
}


and the external signal is a clock with a BCD over 6 nibbles as shown in here:
https://www.yuriystoys.com/2013/07/chinese-caliper-data-format.html

Any help or advice?
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Sun Dec 22, 2019 5:41 am     Reply with quote

All spi_xfer functions need the stream name....
They say they don't, but there are issues unless you use it.

What PIC are you using?.

If the C0/C1 pins are SPI2, then use 'SPI2'. You can't setup a hardware
SPI, without using all three pins. You can override the unused pin after
it is setup, but using only two pins will setup a software SPI, and this
will not support slave operation....
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

spi_xfer_in usage on PIC16F15325
PostPosted: Mon Dec 23, 2019 5:34 am     Reply with quote

Ttelmah wrote:
All spi_xfer functions need the stream name....
They say they don't, but there are issues unless you use it.


Ok. I assume that would mean "data_in = spi_xfer_in(SPI_1,24); in my case"

Quote:

What PIC are you using?.
It's a PIC16F15325

Quote:

If the C0/C1 pins are SPI2, then use 'SPI2'. You can't setup a hardware
SPI, without using all three pins. You can override the unused pin after
it is setup, but using only two pins will setup a software SPI, and this
will not support slave operation....

In my case C0/C1 is SPI1 according to the Microchip datasheet.
Your statement is that I could use the hardware SPI in slave mode(since slave mode is not allowed in software SPI). That means my code will look like this:
Code:
...
#use spi(FORCE_HW, SLAVE, BITS=24, stream=SPI_STREAM)
...
data_in = spi_xfer_in(SPI_STREAM,24);
...


Te compiler still gives error during compilation:
"*** Error 99 "CCS_15325_Micro.c" Line 6(5,54): Option invalid Wrong pins for H/W"

Any advice? Thank you.
temtronic



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

View user's profile Send private message

PostPosted: Mon Dec 23, 2019 6:00 am     Reply with quote

I don't use that PIC but downloaded the datasheet..

That PIC has PPS which probably has to be configured BEFORE you use SPI.

There's a 'Sticky' at the top of this page which should help.
Others who use this PIC , or one with PPS, may reply with help.
jeremiah



Joined: 20 Jul 2010
Posts: 1345

View user's profile Send private message

Re: spi_xfer_in usage on PIC16F15325
PostPosted: Mon Dec 23, 2019 11:11 am     Reply with quote

Momboz wrote:

In my case C0/C1 is SPI1 according to the Microchip datasheet.
Your statement is that I could use the hardware SPI in slave mode(since slave mode is not allowed in software SPI). That means my code will look like this:
Code:
...
#use spi(FORCE_HW, SLAVE, BITS=24, stream=SPI_STREAM)
...
data_in = spi_xfer_in(SPI_STREAM,24);
...


Te compiler still gives error during compilation:
"*** Error 99 "CCS_15325_Micro.c" Line 6(5,54): Option invalid Wrong pins for H/W"

Any advice? Thank you.


You need to tell it which hardware SPI you are using. Nothing in the #use spi() says which. Try adding SPI1
Code:
...
#use spi(SPI1,FORCE_HW, SLAVE, BITS=24, stream=SPI_STREAM)
...
data_in = spi_xfer_in(SPI_STREAM,24);
...


For some compiler versions, specifying the pins but not the SPI module puts it in software SPI mode instead of hardware.

EDIT: also what size is long for your pic (I don't know offhand for 8bit pics)? you will need to have a 32bit value. Specify it as unsigned int32 to be sure.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Mon Dec 23, 2019 2:39 pm     Reply with quote

Yes, his long is only 16bit. Needs to be unsigned int32.


Happy Christmas everyone
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