Using I2C on the Maple Mini

Post here first, or if you can't find a relevant section!
Post Reply
MoffKalast
Posts: 2
Joined: Mon May 25, 2020 2:45 pm

Using I2C on the Maple Mini

Post by MoffKalast »

Hello,

to first give you broad idea what I'm going for, my plan is to do the following:
  • link one TCA9548A to each of the two i2c ports of the maple mini (pins PB6/7 and PB11/10 according to the pinout)
  • add 8 VL53L0X linear lidars to the first one
  • add 4 US42-V2 sonars to the second one
  • read them all sequentially and send the results via serial
That's the end goal for which I'll need both i2c ports to bring the data in with a reasonable delay and to avoid pull up problems. But my first order of business to try is to get one directly connected US42-V2 to print distance data at all. For that the python Raspbery Pi code is simply the following:

Code: Select all

import smbus
import time
i2cbus = smbus.SMBus(1)
address = 0x70

i2cbus.write_byte(address, 0x51)
time.sleep(0.12)
val = i2cbus.read_word_data(address, 0xe1)
print (val >> 8) & 0xff | (val & 0xff), 'cm'
Now I've tried to somewhat reproduce that in a similar manner for the Maple as follows:

Code: Select all

#include<Wire.h>  

#define US42 0x70

void write_byte(int dev_addr, byte addr){
	Wire.beginTransmission(dev_addr);
	Wire.write(addr);
	Wire.endTransmission();
}

int read_word_data(int dev_addr, byte number){
	Wire.requestFrom(dev_addr, number);
	while(Wire.available() == 0);
	return Wire.read();
}

void setup() {
	
	I2C1->sda_pin = PB7;
	I2C1->scl_pin = PB6;
	Wire.begin();
}

void loop() {
	
	write_byte(US42, 0x51);
	delay(120);

	int val = read_word_data(US42,2);
	val = (val >> 8) & 0xff | (val & 0xff);

	Serial.write(val);
}
Unfortunately the code has a minor problem of completely not working at all and my attempts to debug it haven't been very fruitful. I've not been successful in locating a working i2c example for this board either so I don't have much to go from.

So my question is, how to properly set up both of the i2c busses for usage at the same time (why do we have two of them otherwise eh?), and before that - how to even get one working properly in the first place.

Thanks! :)
MoffKalast
Posts: 2
Joined: Mon May 25, 2020 2:45 pm

Re: Using I2C on the Maple Mini

Post by MoffKalast »

I made an attempt to use the maple with the official maple IDE, with which I promptly bricked it by uploading a blink example. Now it disconnects from the com port in a few seconds after being plugged in.

Edit: please use a correct language
Last edited by fpiSTM on Wed May 27, 2020 3:57 am, edited 1 time in total.
Reason: Not appropriate language
ag123
Posts: 1653
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Using I2C on the Maple Mini

Post by ag123 »

the follow up for the maple core is here (libmaple core - this is deemed a community core)
https://github.com/rogerclarkmelbourne/Arduino_STM32
and here is the official core based off HAL
https://github.com/stm32duino/Arduino_Core_STM32

there isn't much documentation per se, but you may find various guides in the wiki
the wiki is the place to start off

these should both work in the current Arduino IDE
https://www.arduino.cc/en/main/software
Last edited by ag123 on Wed May 27, 2020 7:11 am, edited 1 time in total.
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Using I2C on the Maple Mini

Post by fpiSTM »

If you use the STM32 core:
https://github.com/stm32duino/Arduino_Core_STM32

Then use the standard Arduino examples in Wire: I2C scanner,...

With this core you need pull up on each line (SDA/SCL).
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: Using I2C on the Maple Mini

Post by mrburnette »

MoffKalast wrote: Tue May 26, 2020 10:53 am Actually, don't bother answering anymore as I won't be able to test out any suggestions. I made an attempt to use the maple with the official maple IDE, with which I promptly bricked it by uploading a blink example. Now it disconnects from the com port in a few seconds after being plugged in.

I think I should instead go for a microcontroller that doesn't have a 7 years old "latest" documentation and boasts compatibility with ubuntu 10 and <expletive deleted> xp. I can't believe people recommended me this thing.
Dude, your comment is inappropriate and frankly, crude. Keep such bad behavior up and I will ask you be ban from the forum. We must keep these pages clean of filth so that young programmers can utilize the resources without their schools or mentors banning the site.

You have no one but yourself to blame if you did brick your clone, but the fact is you just need to use an ST-Link or a USB-serial dongle to reload an appropriate bootloader. Information can be gathered in these pages:
https://github.com/rogerclarkmelbourne/ ... STM32/wiki


Ray
Post Reply

Return to “General discussion”