I2C with Adafruit Feather STM32F405

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
PMLight
 
Posts: 1
Joined: Thu Nov 24, 2022 12:41 pm

I2C with Adafruit Feather STM32F405

Post by PMLight »

Hey all,
I am very new to CircuitPython and trying to make a very simple I2C communication work.

I already have working arduino code (on a leonardo board) to initialize and set the output of a DAC:

Code: Select all

#include <Wire.h>
#define AD56x5 (0x20 >> 1)
void setup()
{
  Wire.begin();
}

void loop()
{
  // Init
  Wire.beginTransmission(AD56x5);
  Wire.write(0x38); 
  Wire.write(0x00); 
  Wire.write(0x01); 
  Wire.endTransmission();
  delay(100);

  // Vout=Vref
  Wire.beginTransmission(AD56x5);
  Wire.write(0x1F); 
  Wire.write(0xFF); 
  Wire.write(0xFF); 
  Wire.endTransmission();
   delay(1000);
I would now like to do the same with CiruitPython on the Feather STM32F405. From different examples I arrived at this:

Code: Select all

import board
import busio
import time
i2c = busio.I2C(board.SCL, board.SDA)

from adafruit_bus_device.i2c_device import I2CDevice
device = I2CDevice(i2c, 0x10)

while True:
    with device:
        device.write(bytes([0x38]))
        device.write(bytes([0x00]))
        device.write(bytes([0x01]))
        time.sleep(0.001)
    with device:
        device.write(bytes([0x1F]))
        device.write(bytes([0xFF]))
        device.write(bytes([0xFF]))
        time.sleep(1)
        
Obviously I'm missing something, because the CircuitPython code doesn't work (nothing is happening). The adress 0x10 is found, when doing an I2C scan. Can you point out my error?

User avatar
blakebr
 
Posts: 942
Joined: Tue Apr 17, 2012 6:23 pm

Re: I2C with Adafruit Feather STM32F405

Post by blakebr »

Hi,

delay(100) is not the same as time.sleep(.001); time.sleep(0.1) is the same as delay(100).

Bruce

User avatar
adafruit_support_carter
 
Posts: 29056
Joined: Tue Nov 29, 2016 2:45 pm

Re: I2C with Adafruit Feather STM32F405

Post by adafruit_support_carter »

Yep, try fixing timing. Also, can write all the bytes with a single call:

Code: Select all

    with device:
        device.write(bytes([0x38, 0x00, 0x01]))
    delay(0.1)
    with device:
        device.write(bytes([0x1F, 0xFF, 0xFF]))
    delay(0.1)

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”