PIC 18F family - Actual use of WCOL flag (SSPCON1,7)

Thread Starter

atferrari

Joined Jan 6, 2004
4,771
SPI - micro has to transmit only.

I couldn't find a good (practical) use for the WCOL flag (Write collision detect bit).

The way I understand it, I should first write to SSPBUF and then check that flag to see if I was allowed to write. Kind of: "do it and I will tell you if you did right or wrong".

I expected to have a "busy" flag, pretty much like the one in the classic LCD displays that when it is cleared, you know you can go ahead with the next byte.

Is my interpretation wrong?​
 

ErnieM

Joined Apr 24, 2011
8,377
Your interpretation is correct. WCOL tells you you did something bad after you did it.

I believe the BF (Buffer Full) bit flag is what you seek.
 

JohnInTX

Joined Jun 26, 2012
4,787
PIC and other's SPI transmits and receives bytes at the same time. You have to 'receive' even if you just care about transmitting.

To send a byte:
Check BF. If 1, read SSPBUF and discard the value. BF should be 0. (If not, read one more time).

Write your data to TXBUF .The byte will be sent AND a byte will be received and placed in SSPBUF. The BF flag will be set to 1 indicating that a byte has been received and also, that your byte has been transmitted at the same time. That's how you know you can write the next byte.

When BF=1, read and discard SSPBUF. BF will clear.

Write the next byte to TXBUF.

As ErnieM said,
WCOL indicates that you did not wait until the previous byte was sent before writing another. Monitoring BF is how you know. You should monitor WCOL and take appropriate action if its ever set.

BTW: Be sure to check the errata for the specific PIC and for the silicon version you are using. Some of these had more than a few issues with the MSSP module.
 
Last edited:

Thread Starter

atferrari

Joined Jan 6, 2004
4,771
I control a MCP4822, which works OK and I am not using WCOL nor BF.

Thanks for replying.
 
Last edited:
Top