|
|
View previous topic :: View next topic |
Author |
Message |
SvenBraun
Joined: 19 Mar 2016 Posts: 29
|
Error 7 issue with #pin_select |
Posted: Sat Mar 26, 2016 8:30 pm |
|
|
To preface, I'm trying to configure SPI in my program. My microcontroller is PIC18F87J72, which from what I read from the datasheet, it should have SPI capability.
My CCS compiler is 5.024.
These are the lines of code that CCS errors out on:
Code: | #pin_select SCK1OUT=PIN_C5 // CLK
#pin_select SDO1=PIN_C3 // DATA
|
The full error is: "Invalid Pre-Processor directive Invalid Pin ID" (for each line).
I was able to shift over to the following without error:
Code: | #use SPI(DO=PIN_C5,CLK=PIN_C3) |
However, I would prefer to use #pin_select in my program.
I've checked whitespace (with and without) and case-sensitivity, but I haven't been able to clear it up.
What can I do to correct this isssue? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Sun Mar 27, 2016 1:16 am |
|
|
Your chip does not have selectable peripherals (PPS).
Hence no #PIN SELECT ability.....
The key line in the data sheet for #PIN_SELECT:
"When using PPS chips". Your chip does not have PPS.
So you can't use it.
It does have one thing that can move, but this is controlled by fuses, not software selection. CCP2 (to C1, or E7).
If you look at the data sheet, the SPI goes to RC3, RC4 and RC5. No movement ability.
Use:
#use SPI(SPI1, MODE=xx, BAUD=yy)
Which will force the hardware port to be used. Currently you are using software SPI (which can use any pin).
You need/should specify the mode, otherwise it is 'luck' if you happen to get the correct clock/data relationship.
You should also specify the baud rate you want. Otherwise with the hardware port, you may get a faster rate than you can use.
Compare with a chip like the PIC46J50 (which does have PPS). SCK2 is not shown going to any pin. Instead it has a register with five bits determining which chip pin it connects to.
So you can't use #PIN_SELECT, because your chip does not have this ability. Read the data sheet again.....
SPI, yes, your chip does have SPI, and you can use the hardware for this, by either adding 'FORCE_HW', and selecting all three SPI pins (not the two you are currently using), or just specifying SPI1, which is equivalent to:
#use SPI(DO=PIN_C5,CLK=PIN_C3, DI=PIN_C4, FORCE_HW)
Just using 'SPI1' is a lot easier!.... |
|
|
SvenBraun
Joined: 19 Mar 2016 Posts: 29
|
|
Posted: Sun Mar 27, 2016 4:47 pm |
|
|
Thank you! I am new to SPI, so I'm not as confident in how to use it. I was more-so told that we were using SPI, and I couldn't find a good reference. (If you happen to have a good reference for SPI in general, please send it my way!)
I looked at your referenced PIC, and also looked at a previous group's architecture - both datasheets listed PPS as a feature, and I didn't think about it because I've never worked with a chip that had the option; I assumed chips just had it.
Goes to show that even reading the datasheet and CCS Manual, doesn't mean you'll forget about something as basic as checking if your system has what you want it to have.
Thank you for the example! I will re-read that section of the CCS Manual so I have a better understanding of the concept. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Mon Mar 28, 2016 2:50 am |
|
|
The data sheet for your chip, does _not_ list PPS as a feature. Are you sure you are looking at the right data sheet, or have posted the right chip number!...
Don't confuse PPS (peripheral pin select), with SSP (synchronous serial port), which is the 'master' peripheral supporting SPI (and I2C as well).....
Look in the examples!....
EX_SPI.c (for a master)
EX_SPI_SLAVE.c (for a slave)
PPS is a feature on a lot of the later chips, where you can 'move' hardware peripherals to different pins. Gives a lot more flexibility on pins to use, particularly on chips that have a lot of peripherals available. Your chip does not have this. It does have the MSSP (master synchronous serial port). In the examples, the 'slave' example uses the SSP peripheral, while the master uses the software option instead. Just use the SPI1 option to select the hardware, to use the peripheral. |
|
|
|
|
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
|