energia / msp432r-core

MSP432 EMT core for the production silicon (RED LaunchPad only)
2 stars 5 forks source link

Feature Request — Implement Slave I²C on MSP432 #5

Open rei-vilo opened 6 years ago

rei-vilo commented 6 years ago

Is I²C slave implemented on the MSP432?

I was unable to run this very basic program on the MSP432. I tried

However, the very same program runs fine on the old MSP430G2553 on port myWire(0).

The Arduino Uno board is connected to the LaunchPad through a logic level converter with the required pull-up resistors.

#include "Energia.h"
#include "Wire.h"
#define myLED RED_LED

// I2C slave 0x22 command[value]
// - Command
// A: on
// C: off

// MSP432
// 0 = pins 14=SCL 15=SDA
// 1 = pins  9=CLK 10=SDA
//TwoWire myWire(0); // fails
TwoWire myWire(1); // fails also

//// MSP430G2553 - works!
//// 0 = legacy   pins 14=SCL 15=SDA, master and slave
//// 1 = software pins  9=CLK 10=SDA, master only
//TwoWire myWire(0);

void ReceiveEventI2C(int howMany)
{
    uint8_t command = myWire.read();

    switch (command) {
        case 'A':
            digitalWrite(myLED, HIGH);
            break;

        default:
            digitalWrite(myLED, LOW);
    }
}

void RequestEventI2C()
{

}

void setup()
{
    pinMode(myLED, OUTPUT);

    myWire.begin(0x22);
    myWire.onReceive(ReceiveEventI2C);
    myWire.onRequest(RequestEventI2C);
}

void loop()
{
}
#include "Arduino.h"
#include "Wire.h"
#define I2C_SLAVE 0x22

void send(uint8_t command)
{
    Wire.beginTransmission(I2C_SLAVE);
    Wire.write(command);
    Wire.endTransmission();
}

void setup()
{
    Wire.begin();
    Serial.begin(9600);
}

void loop()
{
    Serial.println("A");
    send('A');
    delay(1000);

    Serial.println("C");
    send('C');
    delay(1000);
}
rei-vilo commented 6 years ago

See https://github.com/energia/msp432r-core/blob/57227b88de66a7874435dd50a13e8f612e39d602/cores/msp432/ti/runtime/wiring/Wire.cpp#L135

rei-vilo commented 6 years ago

It looks like slave I²C isn't implemented, so I'm changing the thread to a feature request.

For using the MSP432 as a peripheral, SPI slave and I²C slave are not implemented. Only remains UART. Not very exiting, especially when only I²C is based on interrupts.

The I²C slave implementation on the MSP430 works great, so why the MSP432 shouldn't offer similar feature?