Shop OBEX P1 Docs P2 Docs Learn Events
SPI and I2C issue together — Parallax Forums

SPI and I2C issue together

Andrew BubbleAndrew Bubble Posts: 21
edited 2015-01-31 00:08 in Propeller 1
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

Comments

  • twm47099twm47099 Posts: 867
    edited 2015-01-30 16:00
    I'm not sure if this will help, but I have written an SPI library that uses a separate cog and PASM to make it faster than the Simple Libraries version.

    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
  • Andrew BubbleAndrew Bubble Posts: 21
    edited 2015-01-31 00:08
    Hi 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
Sign In or Register to comment.