SPI Legacy - Clock Idle State wont Change

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

SPI Legacy - Clock Idle State wont Change

Post by Jay Dee »

Hi,
This could be a bug or I've done something dumb but i cant change the SPI clock polarity. (not sure on the edge setting either)

To simplify things and remove other possible issues, like a pull up somewhere else, this testing was done with a stand alone ECIO 40P (18F4455) and running FC 5.5.2.1
Irrespective of what settings I put in the SPI properties 'SPI CLOCK Polarity', in Hardware the clock polarity is always high.

Checking the 18F4455 data sheet, these settings are set by writing to the required register.
Register SSPCON1: bit 4 (ClocKPolarity)
I may also need to change
Register SSPSTAT: bit 6 (Transmits clock select bit, i.e. edge)

If the FC properties settings are not working, could I set these via a C code box? What C code do I need to both read the existing and write a new register value ? :?

Backgound info: I have several SPI devices on one bus, some are quite tolerant of various SPI configurations, others need specific settings to correctly work. I seem to be getting data back that is all shifted by 1 bit...I suspect its tripping up on the how it reads/interprets the first bit.

Any thoughts? :)
Thanks, J.

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: SPI Legacy - Clock Idle State wont Change

Post by Jay Dee »

Hi guys, before we drop into the weekend, could anyone give the C code to.
A) read a specific registers value back into a flowcode variable
B) write to a register
Cheers,
J.

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: SPI Legacy - Clock Idle State wont Change

Post by LeighM »

C use example attached

Regards,
Leigh
Attachments
18F4455_C.fcf
(6 KiB) Downloaded 234 times

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: SPI Legacy - Clock Idle State wont Change

Post by Jay Dee »

Ahhh :oops:
Well, no bug but something I just learnt...
If you have the CAN initialize macro AFTER the SPI initialize macro, the SPI settings are set to the default CAN values, this includes my troublesome SPI idlie bit. Obviously if you are using the internal CAN this may not be applicable.
So solution, make sure the CAN initialize macro is always before the SPI initialize.

I have not done extensive testing on the following assumption but If you have several SPI devices on a single buss and they require slightly different SPI settings you will still need to use lines of C code to toggle about the required config bits.

As Leigh showed me.
The C code
sspcon1 = sspcon1 | 0x10;
toggles the 5th bit in the sspcon1 register, which for the 18F5544, toggles the SPI clock idle state (idle high or idle low). All of this info was in the Microchip datasheet.
Well, hopefully that has sorted much of my problems and I've learnt a fair bit more on SPI !! :D
Thanks again Leigh.
J.

Post Reply