Richard-Gemmell / teensy4_i2c

An I2C library for the Teensy 4. Provides slave and master mode.
MIT License
92 stars 19 forks source link

Simple Teensy 4.1 Slave, what am I missing? #21

Closed arjuna-dev closed 2 years ago

arjuna-dev commented 2 years ago

I am trying to send data from a Teensy 4.1 as am I2C slave.

Here is an image from a logic analyzer of what I am sending to it:

SPI_M4_logic

And I am using the basic example (just modifying the slave address):

#include <Arduino.h>
#include <i2c_driver.h>
#include <i2c_driver_wire.h>

void requestEvent();

int led = LED_BUILTIN;

void setup()
{
  pinMode(led, OUTPUT);
  Wire.begin(0x22);
  Wire.onRequest(requestEvent); // register event
}

void loop()
{
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
  digitalWrite(led, HIGH);      // briefly flash the LED
  Wire.write(0xFF);
  digitalWrite(led, LOW);
}

I am using pins 16 and 17 as a slave I2C in the teensy.

It seems that requestEvent() never kicks in.

Thanks!

Richard-Gemmell commented 2 years ago

Hi, It's a simple mistake. Your code is using Wire which is tells it to use pins 18 & 19. Change all references to Wire1 and it should work. e.g. Wire1.begin(0x22).

The logic analyzer is showing that the master is working and configured correctly.

cheers, Richard