View previous topic :: View next topic |
Author |
Message |
mesh
Joined: 29 Mar 2018 Posts: 3 Location: Nashville
|
compile error, missing SPI_CLK_DIV_4 |
Posted: Thu Mar 29, 2018 5:41 pm |
|
|
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: 9476 Location: Greensville,Ontario
|
|
Posted: Thu Mar 29, 2018 6:41 pm |
|
|
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
|
|
Posted: Thu Mar 29, 2018 6:47 pm |
|
|
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: 19836
|
|
Posted: Fri Mar 30, 2018 12:40 am |
|
|
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
|
|
Posted: Fri Mar 30, 2018 7:20 am |
|
|
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 |
|
 |
|