Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 11 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
9 years, 11 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.
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