PIC18F25K42 problems with SPI

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
User avatar
Bruno
Posts: 67
Joined: Thu Jan 18, 2018 2:11 pm
Been thanked: 21 times
Contact:

PIC18F25K42 problems with SPI

Post by Bruno »

Hi at all
I have a configuration problem with the SPI module
of the PIC18F25K42 that I have chosen because it has the ADC with 12bit resolution.
The SPI, if configured as a hardware module does not work and blocks the cycle, if configured as software it works well.
I2C also has the same problems.
Is there anyone who has had the same problems?

Thank you

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC18F25K42 problems with SPI

Post by medelec35 »

Hi Bruno.
If you want to use both SPI and I2C in hardware mode then that would not be a possibility with PIC18FXXK42 range of devices.
This is because the I2C hardware was dropped due to the registers being completely different to all other devices.
The K42 range was only added as it was a user request.
As an alternative what about the K22 or K80 range?
If you want to sick to K42 then you will need to stay with I2C software mode.
Martin

User avatar
Bruno
Posts: 67
Joined: Thu Jan 18, 2018 2:11 pm
Been thanked: 21 times
Contact:

Re: PIC18F25K42 problems with SPI

Post by Bruno »

Hi Martin
Thanks for your reply, although I was hoping you would give better news !!!! :( :(
I need fifteen 12bit ADCs and unfortunately there aren't many with these features.
For now, I'll use the software SPI, then I'll try to figure out how to configure the hardware

best regards

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PIC18F25K42 problems with SPI

Post by medelec35 »

I did look up 12bit adc before replying. I have narrowed the search down to PIC18F25K80 or PIC18F26K80 as they both have 28pins and both have 12Bit ADC
There are more devices.
What I did was to go to MICROCHIP ADVANCED PART SELECTOR
Select CPU Type 8-bit MCU
Pin count 28 , 28
ADC Resolution 12,12
A total of 31 parts was found
After adding the second lot of 12 the K22 range disappeared, so could have been a bug.
I hope you find this more helpful?
Martin

User avatar
Bruno
Posts: 67
Joined: Thu Jan 18, 2018 2:11 pm
Been thanked: 21 times
Contact:

Re: PIC18F25K42 problems with SPI

Post by Bruno »

Thanks Martin
I visited the Microchip site, but the K80 series only has eight 12bit ADCs and I need sixteen ADCs.
The others, unfortunately, are not implemented in FC, such as Pic16F18456 or PIC18F25Q43

User avatar
Bachman
Posts: 116
Joined: Sun Sep 07, 2014 11:37 am
Location: Hungary
Has thanked: 9 times
Been thanked: 53 times
Contact:

Re: PIC18F25K42 problems with SPI

Post by Bachman »

C code, SPI example (check datasheet for explanation):

Setup SPI module:

Code: Select all

SPI1CON1 = 0b11000000;
SPI1CON2 = 0b00000011;
SPI1CLK = 0;
SPI1BAUD = 39;
SPI1CON0 = 0b10000011;
Using SPI module:

Code: Select all

cs = 0;
SPI1TXB = 0;
while (!PIR3bits.SPI1RXIF);
data_0 = SPI1RXB;
SPI1TXB = 0;
while (!PIR3bits.SPI1RXIF);
data_1 = SPI1RXB;
cs = 1;
cs: Chip select, active low. Use a simple output for it. Before setup, make sure to set the pin to input or output, set the PPS registers.

User avatar
Bruno
Posts: 67
Joined: Thu Jan 18, 2018 2:11 pm
Been thanked: 21 times
Contact:

Re: PIC18F25K42 problems with SPI

Post by Bruno »

Hi Bachman
Thank you for your suggestion
I would like to understand if it is possible to integrate the C code in the PIC_CAL_SPI :D :D
best regards

User avatar
Bruno
Posts: 67
Joined: Thu Jan 18, 2018 2:11 pm
Been thanked: 21 times
Contact:

Re: PIC18F25K42 problems with SPI

Post by Bruno »

Hi at all
I think I have solved the problem of the "Standard" configuration of the SPI module of the Pic 18Fxx42 series, thanks also to Bachman's suggestion. The only problem is the configuration of the prescaler which has a different setting from the other PICs.
I forced the default values that are set in the SPI configuration mask: for example, the value to pass to the variable PR_SCALE, is 15 to have a x32 division factor, as also shown in the photo.
It would be nice if the FC team modified the PIC_CAL_SPI.c file to add the few instructions.
Below is the C code to add at the beginning of the program.

best regards

/ *
Set_SPI_1
* /
SPI1CON2 = 0x03; // 0b00000011
SPI1CLK = 0x00;
SPI1CON0 = 0x83; // 0b10000011
Attachments
Image1.jpeg
Image1.jpeg (70.34 KiB) Viewed 12206 times

Post Reply