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 support@ccsinfo.com

compile error, missing SPI_CLK_DIV_4

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



Joined: 29 Mar 2018
Posts: 3
Location: Nashville

View user's profile Send private message Visit poster's website

compile error, missing SPI_CLK_DIV_4
PostPosted: Thu Mar 29, 2018 5:41 pm     Reply with quote

Hi folks,

New PIC dev here and new to CCS. Just inherited a long lived PIC18 CCS project, where to goal is to move to PIC24 and also replace some obsolete external parts.

Old: 18F67K22
New: 24FJ1024GB610
CCS: 5.077

In the legacy code:
Code:
setup_spi2 (SPI_MASTER | SPI_CLK_DIV_4 | SPI_MODE_3 | SPI_SAMPLE_AT_END);

does not compile, with:
*** Error 12 xxxx Undefined identifier SPI_CLK_DIV_4

Is that missing on purpose? Suggestions to fix? The ccs_c_manual.pdf lists that item in the docs, so not sure what the next step is.
_________________
Matthew
temtronic



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

View user's profile Send private message

PostPosted: Thu Mar 29, 2018 6:41 pm     Reply with quote

While I don't use that 24 series PIC...

You'll have to look at the PIC24 header to see what options are valid for the SPI commands.
It may be a 'syntax' problem where the option is avalable, it's just called something else.
mesh



Joined: 29 Mar 2018
Posts: 3
Location: Nashville

View user's profile Send private message Visit poster's website

PostPosted: Thu Mar 29, 2018 6:47 pm     Reply with quote

Yep, I looked at the header and it is missing all DIV options. Other Pic24 headers included various DIV options...

temtronic wrote:
While I don't use that 24 series PIC...

You'll have to look at the PIC24 header to see what options are valid for the SPI commands.
It may be a 'syntax' problem where the option is avalable, it's just called something else.

_________________
Matthew
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Fri Mar 30, 2018 12:40 am     Reply with quote

The simple answer is the chip doesn't have this.
The options in setup are always based on the chip's abilities. In this case the chip has a 13bit baud rate generator (more like PIC18 I2C), instead of having prescalers.
Now the easiest answer is to use #USE SPI rather than setup_spi. Setup_spi is the 'old' syntax, and has far fewer abilities. With #USE SPI, you just specify the baud rate you want, and the compiler will work out the combinations of BRG and clock, to try to get as close to this (never over it) as it can. However you would then need to switch to using spi_xfer rather than spi_read & write.
The great thing about this is it would then be portable to whatever chip you wanted in the future.
However if you want to use setup_spi, then look again at it in the header. You will see that it's syntax is specified as:

void setup_spi(unsigned int16 mode, unsigned int32 baud);

So your setup would be:

setup_spi2 (SPI_MASTER | SPI_MODE_3 | SPI_SAMPLE_AT_END, 4000000);

To give 4MHz.
mesh



Joined: 29 Mar 2018
Posts: 3
Location: Nashville

View user's profile Send private message Visit poster's website

PostPosted: Fri Mar 30, 2018 7:20 am     Reply with quote

Thank you! I fixed a few other compile issues after noticing issues like this, but for some reason missed this one. Thank you!

Ttelmah wrote:
The simple answer is the chip doesn't have this.
The options in setup are always based on the chip's abilities. In this case the chip has a 13bit baud rate generator (more like PIC18 I2C), instead of having prescalers.
Now the easiest answer is to use #USE SPI rather than setup_spi. Setup_spi is the 'old' syntax, and has far fewer abilities. With #USE SPI, you just specify the baud rate you want, and the compiler will work out the combinations of BRG and clock, to try to get as close to this (never over it) as it can. However you would then need to switch to using spi_xfer rather than spi_read & write.
The great thing about this is it would then be portable to whatever chip you wanted in the future.
However if you want to use setup_spi, then look again at it in the header. You will see that it's syntax is specified as:

void setup_spi(unsigned int16 mode, unsigned int32 baud);

So your setup would be:

setup_spi2 (SPI_MASTER | SPI_MODE_3 | SPI_SAMPLE_AT_END, 4000000);

To give 4MHz.

_________________
Matthew
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