SPI and I2C issue together
Andrew Bubble
Posts: 21
Hi all
I have a strange issue concerning a propeller application I am developing. The issue concerns the fact I have an SPI device and an I2C in the same application. I have had each working separately in different applications with no issues. I have tried running the I2C in one cog and the SPI in another but the results are the same. The problem manifests itself as corrupt data read from the SPI device.
My application has a 16 channel Led PWM board driven by the I2C library and a Nordic nRF24L01 2.4 GhZ radio module communicated by the SPI library. I have one propeller with Nordic module sending cyclic data, this is received by a second propeller board also with a Nordic radio module but also a 16 channel PWM Led board. The plan was to send the received data to the PWM Led board but all I receive is random data. I have put some test code to print the received data to the SimpleIDE terminal.
The two lines below are the two sections of code for each module. If I comment out the first line then the data printed from the receive part of the Nordic module displays the correct data but if I re enable the first line then random data is displayed.
cog_run(&LED_Lights, 70); // 16 Channel PWM Board
cog_run(&Nordic, 70); // Nordic Radio Module
Are there any issues running the I2C and SPI library in the same application I should be aware of. One thing that puzzles me is the way the I2C and SPI are declared, see as below.
static I2C_COGDRIVER Dev;
static I2C *PCA9685;
static spia_t *nRF24L01;
I noticed the I2C has first a COGDRIVER Dev declaration but not the spi.
Regards Andrew
I have a strange issue concerning a propeller application I am developing. The issue concerns the fact I have an SPI device and an I2C in the same application. I have had each working separately in different applications with no issues. I have tried running the I2C in one cog and the SPI in another but the results are the same. The problem manifests itself as corrupt data read from the SPI device.
My application has a 16 channel Led PWM board driven by the I2C library and a Nordic nRF24L01 2.4 GhZ radio module communicated by the SPI library. I have one propeller with Nordic module sending cyclic data, this is received by a second propeller board also with a Nordic radio module but also a 16 channel PWM Led board. The plan was to send the received data to the PWM Led board but all I receive is random data. I have put some test code to print the received data to the SimpleIDE terminal.
The two lines below are the two sections of code for each module. If I comment out the first line then the data printed from the receive part of the Nordic module displays the correct data but if I re enable the first line then random data is displayed.
cog_run(&LED_Lights, 70); // 16 Channel PWM Board
cog_run(&Nordic, 70); // Nordic Radio Module
Are there any issues running the I2C and SPI library in the same application I should be aware of. One thing that puzzles me is the way the I2C and SPI are declared, see as below.
static I2C_COGDRIVER Dev;
static I2C *PCA9685;
static spia_t *nRF24L01;
I noticed the I2C has first a COGDRIVER Dev declaration but not the spi.
Regards Andrew
Comments
I
The latest is located in post 67 of this thread (along with some examples):
http://forums.parallax.com/showthread.php/157441-Can-SPI-in-Simple-Libraries-be-speeded-up?p=1310288#post1310288
Tom
Thanks for the reply but I am already using this library. I was having trouble last year with SPI speed and someone point me to this library.
I have found the problem and it was nothing to do with the libraries. In my routine that updates the RGB LED's I had place a two lines of code that pulsed an output
high(1) and low(1) I used this to monitor on an oscilloscope to measure the timing of the update. It so happens that this pin was used by the SPI to talk to the Nordic module. I found by commenting sections of code out to see where the problem lie and noticed it.
I apologise as this is my fault and should of looked closer.
Thanks again and the SPI is a great library.
Regards Andrew