SPI between two 12F1822 PIC's
Moderator: Benj
SPI between two 12F1822 PIC's
Hi,
I need some assistance on getting either SPI or I2C working between 2 12F1822 PIC's please.
I am using the 30 day free trial of Flowcode 7.
Problem 1
Both chips are running at 32mhz, however I am unable to compile the TX flowchart to hex as Flowcode is reporting an " ^ (192) undefined identifier "osccon"
"
The value I am using in the C prompt is "osccon = 0xF0;" and then setting the chip speed to 32000000 in the project options.
Has there been changes to how the oscillator is set and I no longer need to include the osccon statement?
Problem 2
I am trying to send a byte from 1 pic to the next. I do not require any return communication from slave to master. To check whether I receive anything on the slave, I am flashing an LED connected to RA5 as I do not have a scope I can use.
At this stage I am trying SPI and have connected as below
I have set the SPI channel to software so expect the connections below to work
From TX -> RA0 to RX -> RA2 (SDO to SDI)
From TX -> RA1 to RX -> RA1 (CLK to CLK)
From TX -> RA2 to RX -> RA0 (SDI to SDO)
In the 12f1822_SPI_TX flowchart, I am initialising SPI and then running through a loop by sending a byte using sendchar feature.
In the 12f1822_SPI_RX flowchart, I am initialising and then reading the char, converting it to a byte and then flashing RA5 to see if any data has been received. I am expecting to see 5 flashes, followed by 4 flashes, followed by 3, etc.
As I am unable to compile, I can't test the routine.
Please assist.
Regards
Conroy
I need some assistance on getting either SPI or I2C working between 2 12F1822 PIC's please.
I am using the 30 day free trial of Flowcode 7.
Problem 1
Both chips are running at 32mhz, however I am unable to compile the TX flowchart to hex as Flowcode is reporting an " ^ (192) undefined identifier "osccon"
"
The value I am using in the C prompt is "osccon = 0xF0;" and then setting the chip speed to 32000000 in the project options.
Has there been changes to how the oscillator is set and I no longer need to include the osccon statement?
Problem 2
I am trying to send a byte from 1 pic to the next. I do not require any return communication from slave to master. To check whether I receive anything on the slave, I am flashing an LED connected to RA5 as I do not have a scope I can use.
At this stage I am trying SPI and have connected as below
I have set the SPI channel to software so expect the connections below to work
From TX -> RA0 to RX -> RA2 (SDO to SDI)
From TX -> RA1 to RX -> RA1 (CLK to CLK)
From TX -> RA2 to RX -> RA0 (SDI to SDO)
In the 12f1822_SPI_TX flowchart, I am initialising SPI and then running through a loop by sending a byte using sendchar feature.
In the 12f1822_SPI_RX flowchart, I am initialising and then reading the char, converting it to a byte and then flashing RA5 to see if any data has been received. I am expecting to see 5 flashes, followed by 4 flashes, followed by 3, etc.
As I am unable to compile, I can't test the routine.
Please assist.
Regards
Conroy
- Attachments
-
- Projects.7z
- (2.67 KiB) Downloaded 251 times
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: SPI between two 12F1822 PIC's
Hi Conroy,
I can help with 1.
See here on correct format of osccon and other registers for Flowcode V7
Then Flowchart should compile OK.
Martin
I can help with 1.
See here on correct format of osccon and other registers for Flowcode V7
Then Flowchart should compile OK.
Martin
Martin
Re: SPI between two 12F1822 PIC's
Hi Martin,
Changes to uppercase and it compiled fine. Thanks for your assistance. Now for some more testing...
Regards
Conroy
Changes to uppercase and it compiled fine. Thanks for your assistance. Now for some more testing...
Regards
Conroy
Re: SPI between two 12F1822 PIC's
Hi guys,
I have managed to compile both flowcharts.
A few facts I have checked to facilitate troubleshooting:
When I simulate the sending on the TX flowchart, the SPI out (green arrow) flashes as expected.
Unable to check the RX flowchart in simulation mode.
When I place the PIC's in the circuit The LED on the RX chip flashes non-stop. I stopped counting at 400 flashes...
I expect the problem to be related to one of 2 issues:
a) when I send a char from the TX, will the number 5 be sent in the correct format for the RX to receive?
b) I could not see anywhere in the config where one would set up the RX as a slave and by using the same SPI component, how does the RX chip know it is a slave?
I would really appreciate any assistance offered.
Regards
Conroy
I have managed to compile both flowcharts.
A few facts I have checked to facilitate troubleshooting:
When I simulate the sending on the TX flowchart, the SPI out (green arrow) flashes as expected.
Unable to check the RX flowchart in simulation mode.
When I place the PIC's in the circuit The LED on the RX chip flashes non-stop. I stopped counting at 400 flashes...
I expect the problem to be related to one of 2 issues:
a) when I send a char from the TX, will the number 5 be sent in the correct format for the RX to receive?
b) I could not see anywhere in the config where one would set up the RX as a slave and by using the same SPI component, how does the RX chip know it is a slave?
I would really appreciate any assistance offered.
Regards
Conroy
- Attachments
-
- Projects.7z
- (2.69 KiB) Downloaded 242 times
Re: SPI between two 12F1822 PIC's
Hi guys,
I found a rookie mistake in my RX file as I did not decrease the variable flashcount every time I did the loop.
The results in this version si that there is no flashing on the LED so I suspect that the RX chip is not receiving any data from the TX chip.
Any ideas anyone.... please...
Regards
Conroy
I found a rookie mistake in my RX file as I did not decrease the variable flashcount every time I did the loop.
The results in this version si that there is no flashing on the LED so I suspect that the RX chip is not receiving any data from the TX chip.
Any ideas anyone.... please...
Regards
Conroy
- Attachments
-
- Projects.7z
- (2.87 KiB) Downloaded 230 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: SPI between two 12F1822 PIC's
Hi Conroy,
The problem is your RX program is using a SPI Master component. Ideally you need the SPI to be configured into slave mode. The master component will drive the clock pin when transmitting or receiving, the slave component will on the otherhand be driven by the master's clock signal.
I have a example C project here that creates a SPI slave but it's not a perfect example as there's other things going on in the program and it's for a 16-bit PIC device.
https://github.com/RowlandTechnology/MU ... Firmware.c
You're interested in these functions in the C file.
initSPISlave() - Sets up the SPI peripheral in slave mode and enables interrupts
_ISR _SPI1RXInterrupt(void) - SPI receive interrupt, called when a full 8-bit SPI transaction has been clocked in
My advise would be to try and cobble together the SPI slave for the RX program using C icons and referring to the device datasheet. Post what you have and the problems you run into and we will have a look for you and hopefully help you get it working.
A SPI Slave component is on our wish list but there are problems surrounding it that I won't go into here.
Another option might be I2C as we already have a slave component to support this. UART comms is probably the easiest way to communicate between micros as there is no master / slave barriers to overcome.
The problem is your RX program is using a SPI Master component. Ideally you need the SPI to be configured into slave mode. The master component will drive the clock pin when transmitting or receiving, the slave component will on the otherhand be driven by the master's clock signal.
I have a example C project here that creates a SPI slave but it's not a perfect example as there's other things going on in the program and it's for a 16-bit PIC device.
https://github.com/RowlandTechnology/MU ... Firmware.c
You're interested in these functions in the C file.
initSPISlave() - Sets up the SPI peripheral in slave mode and enables interrupts
_ISR _SPI1RXInterrupt(void) - SPI receive interrupt, called when a full 8-bit SPI transaction has been clocked in
My advise would be to try and cobble together the SPI slave for the RX program using C icons and referring to the device datasheet. Post what you have and the problems you run into and we will have a look for you and hopefully help you get it working.
A SPI Slave component is on our wish list but there are problems surrounding it that I won't go into here.
Another option might be I2C as we already have a slave component to support this. UART comms is probably the easiest way to communicate between micros as there is no master / slave barriers to overcome.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: SPI between two 12F1822 PIC's
Hi Ben,
Tx for your quick response.
I think the easiest will be to follow your advice and use UART.
I will let you know how I get on.
Tx again...
Rgards
Conroy
Tx for your quick response.
I think the easiest will be to follow your advice and use UART.
I will let you know how I get on.
Tx again...
Rgards
Conroy
Re: SPI between two 12F1822 PIC's
Hi Ben,
I am really starting to feel STUPID as I have been struggling for 3 days to get 2 PIC's to talk to each other. Using Flowcode, I have tried SPI, I2C and now UART as per your recommendation.
I have connected TX RA0 to RX RA1
I have connected TX RA1 to RX RA0
In the 12f1822_SPI_TX flowchart, I am initialising UART and then running through a loop by sending a byte using sendnumber feature.
In the 12f1822_SPI_RX flowchart, I am initialising and then reading the number and then flashing RA5 to see if any data has been received. I am expecting to see 5 flashes, followed by 4 flashes, followed by 3, etc.
All I see is a continuous flashing of the LED.
Would really appreciate assistance.
Regards
Conroy
I am really starting to feel STUPID as I have been struggling for 3 days to get 2 PIC's to talk to each other. Using Flowcode, I have tried SPI, I2C and now UART as per your recommendation.
I have connected TX RA0 to RX RA1
I have connected TX RA1 to RX RA0
In the 12f1822_SPI_TX flowchart, I am initialising UART and then running through a loop by sending a byte using sendnumber feature.
In the 12f1822_SPI_RX flowchart, I am initialising and then reading the number and then flashing RA5 to see if any data has been received. I am expecting to see 5 flashes, followed by 4 flashes, followed by 3, etc.
All I see is a continuous flashing of the LED.
Would really appreciate assistance.
Regards
Conroy
- Attachments
-
- Projects.7z
- (2.74 KiB) Downloaded 247 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: SPI between two 12F1822 PIC's
Hi Conroy,
I've fiddled with your programs a bit so hopefully they will work now, please let me know how you get on.
I've fiddled with your programs a bit so hopefully they will work now, please let me know how you get on.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: SPI between two 12F1822 PIC's
Hi Ben,
I now have an LED that does nothing for around 5 seconds and then starts flashing non-stop.
I have read a number of posts and have not come across any solution so am still relying on your or any other members assistance please.
Regards
Conroy
I now have an LED that does nothing for around 5 seconds and then starts flashing non-stop.
I have read a number of posts and have not come across any solution so am still relying on your or any other members assistance please.
Regards
Conroy
Re: SPI between two 12F1822 PIC's
Hi,
Would anyone recommend 10K pull-up resistors on TX and RX?
As mentioned in previous post, the file flowcharts in the post from Ben result in a continuous blinking LED.
Regards
Conroy
Would anyone recommend 10K pull-up resistors on TX and RX?
As mentioned in previous post, the file flowcharts in the post from Ben result in a continuous blinking LED.
Regards
Conroy
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: SPI between two 12F1822 PIC's
Hi Conroy,
I've had another play and think I've found the problem. You were sending the value as a ASCII number rather then a byte so this would have been passing a much higher number of counts then expected.
5 would have been passing the value '5' which is decimal 53.
http://www.asciitable.com/
Hopefully this should work better for you.
I've had another play and think I've found the problem. You were sending the value as a ASCII number rather then a byte so this would have been passing a much higher number of counts then expected.
5 would have been passing the value '5' which is decimal 53.
http://www.asciitable.com/
Hopefully this should work better for you.
No this is not required, unless you want to be able to power up one micro when the other micro could potentially be powered off.Would anyone recommend 10K pull-up resistors on TX and RX?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: SPI between two 12F1822 PIC's
Hi Ben,
I was looking at the same thing this morning and will try your suggestion later when I get home.
Thanks for all your support and I will let you know how I get on.
Regards
Conroy
I was looking at the same thing this morning and will try your suggestion later when I get home.
Thanks for all your support and I will let you know how I get on.
Regards
Conroy
Re: SPI between two 12F1822 PIC's
Hi Ben,
It is now sorted and the 2 PIC's are communicating flawlessly. Tx for your assistance and support, much appreciated.
Regards
Conroy
It is now sorted and the 2 PIC's are communicating flawlessly. Tx for your assistance and support, much appreciated.
Regards
Conroy
Re: SPI between two 12F1822 PIC's
Hi guys,
Using the flowcharts above as a basis, I have expanded on the code and am trying to pass a value (which is a number containing a value between 0 and 255) from one PIC to the next. I have found it works perfectly except when the value being passed is equal to 4 or less.
In this instance the receiver chip freezes and needs to be reset.
Some investigation done indicates that one needs to reset to FERR bit of the RCSTA register. I have inserted the C command below and it compiles fine.
clear_bit(rcsta,FERR);
Before resetting the bit needlessly and sacrificing performance, I would appreciate assistance in reading the value of the RCSTA, FERR bit into a variable and thought that I would evaluate the value of FCV_freeze before clearing the FERR bit.
I tried entering another C command as below
FCV_freeze=(rcsta,FERR);
When I compile the flowchart, I receive errors regarding closing parentheses and missing semi colons.
Any assistance would be appreciated.
Regards
Conroy
Using the flowcharts above as a basis, I have expanded on the code and am trying to pass a value (which is a number containing a value between 0 and 255) from one PIC to the next. I have found it works perfectly except when the value being passed is equal to 4 or less.
In this instance the receiver chip freezes and needs to be reset.
Some investigation done indicates that one needs to reset to FERR bit of the RCSTA register. I have inserted the C command below and it compiles fine.
clear_bit(rcsta,FERR);
Before resetting the bit needlessly and sacrificing performance, I would appreciate assistance in reading the value of the RCSTA, FERR bit into a variable and thought that I would evaluate the value of FCV_freeze before clearing the FERR bit.
I tried entering another C command as below
FCV_freeze=(rcsta,FERR);
When I compile the flowchart, I receive errors regarding closing parentheses and missing semi colons.
Any assistance would be appreciated.
Regards
Conroy
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: SPI between two 12F1822 PIC's
If you post your flowchart that produces the error, I will take a look look at it for you.
Martin