8 years, 5 months ago.

Problem running two communication protocols on one mbed

I'm working on a project which involves receiving information on a central mbed connected to another mbed through spi (which is itself connected to ultrasonic sensors) and then relaying that information to another mbed through 12c which will control an RC car. Problem is that i keep getting a delay of about 4 seconds during transmission. i have checked the code and there is no wait hindering it., Can anyone help with this??

1 Answer

8 years, 5 months ago.

It sounds like you have a timeout which is causing the delay. Perhaps you have an unfinished transmission on I2C (no ack) that is delaying things? You might need to post your code up here for more help.

+1 - Need code

posted by Christian Lerche 01 Dec 2015

data

#include "mbed.h" //MASTER
#include "esc.h"

I2C i2c_port(p28, p27);        // Configure a serial port, pins 9 and 10 are sda,scl
Serial pc(USBTX, USBRX); // tx, rx
SPI ser_port(p11, p12, p13);    // mosi, miso, sclk, ssel
DigitalOut greenled(p5);   //greenled
DigitalOut whiteled(p6); //red led
DigitalOut orangeled(p7); //orange led
DigitalOut yellowled(p14);        //yellow red
DigitalOut cs(p14);        //this acts as “slave select”
const int addr = 0x52;    // define the I2C slave address, an arbitrary even number
char switch_word ;        //word we will send
char recd_val;            //value return from slave
  
int main() {
  while (1){
    //Default settings for SPI Master chosen, no need for further configuration    
    //Set up the word to be sent, by testing switch inputs
    ser_port.format(8,0);        // Setup the SPI for 8 bit data, Mode 0 operation
  ser_port.frequency(1000000); // Clock frequency is 1MHz
    switch_word=0xA0; //set up a recognisable output pattern
   
    wait(0.002);   

    
    cs = 0;                                //select slave
    recd_val=ser_port.write(switch_word);  //send switch_word and receive data
    cs = 1;      
      i2c_port.start();          //force a start condition
    i2c_port.write(addr);      //send the address
    i2c_port.write(recd_val); //send one byte of data, ie switch_word
    i2c_port.stop();           //force a stop condition         
posted by Ehidiamen U-Mark 02 Dec 2015

The problem is that there is a three second delay between when the data is received through the spi port and when it is sent out through the 12c ports.

posted by Ehidiamen U-Mark 02 Dec 2015