program modification
Re: program modification
I want to scan I2C2, which is pins PB10 and PB11
-
- Posts: 505
- Joined: Fri Dec 27, 2019 4:53 pm
- Location: Munich, Germany
- Contact:
Re: program modification
Use:
(remove of shift up commented out line in between) and replace all occurrences of Wire by Wire2.
Code: Select all
Adafruit_SSD1306 Display (128, 64, &Wire2, OLED_RESET);
Re: program modification
Code: Select all
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire_slave.h>
//use IIC2
//TwoWire WIRE2 (2,I2C_FAST_MODE);
//#define Wire WIRE2
//////////////////
#define OLED_RESET -1 // use -1 if no reset pin on OLED board
// use second I2C bus on STM32F103
// TwoWire Wire2(SDA2, SCL2);
TwoWire Wire2(PB11, PB10);
Adafruit_SSD1306 Display
// below is for a 128x64 OLED. Other option is 128x32 for smaller OLED
Adafruit_SSD1306 Display (128, 64, &Wire2, OLED_RESET);
//////////////////
void setup() {
Serial.begin(115200);
Wire.begin();
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++) {
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address, HEX);
nDevices++;
}
else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address, HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found");
else
Serial.println("done");
delay(5000); // wait 5 seconds for next scan
}
/*
////////////////////
Display1.begin(SSD1306_SWITCHCAPVCC, 0x3C); // if nothing is displayed using 0x3C, try 0x3D
// Display1
Display1.clearDisplay();
Display1.setTextSize(2);
Display1.setTextColor(WHITE, BLACK);
Display1.setCursor(0, 0 );
Display1.println("Display");
Display1.println("I2C #2 @ 3C");
Display1.display();
////////////////////
*/
scanner_i2c2_duino:38:25: error: no matching function for call to 'TwoWire::TwoWire(<anonymous enum>, <anonymous enum>)'
TwoWire Wire2(PB11, PB10);
^
In file included from /Users/Documents/Arduino/scanner_i2c2_duino/scanner_i2c2_duino.ino:27:0:
/Users/Documents/Arduino/hardware/Arduino_STM32-master-3/STM32F1/libraries/WireSlave/src/Wire_slave.h:91:3: note: candidate: TwoWire::TwoWire(i2c_dev*)
TwoWire(i2c_dev* i2cDevice);
^~~~~~~
/Users/Documents/Arduino/hardware/Arduino_STM32-master-3/STM32F1/libraries/WireSlave/src/Wire_slave.h:91:3: note: candidate expects 1 argument, 2 provided
scanner_i2c2_duino:40:1: error: 'Adafruit_SSD1306' does not name a type
Adafruit_SSD1306 Display
^~~~~~~~~~~~~~~~
Multiple libraries were found for "Wire_slave.h"
Used: /Users/Documents/Arduino/hardware/Arduino_STM32-master-3/STM32F1/libraries/WireSlave
Not used: /Users/Documents/Arduino/hardware/Arduino_STM32-master-3/STM32F1/libraries/Wire
exit status 1
no matching function for call to 'TwoWire::TwoWire(<anonymous enum>, <anonymous enum>)'
Re: program modification
Because the problem with I2C2 I try using I2C on pins PB8 and PB9 , this program is working on pins PB6 an d PB7 but not on PB8 and PB9 pins. I scanned pins PB8 and PB9 and PB6 an d PB7 and have for both address 0x27.
Code: Select all
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x3F for a 16 chars and 2 line display
//LiquidCrystal_I2C lcd(0x3F, 16, 2);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
lcd.begin();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print(" I2C LCD with ");
lcd.setCursor(0,1);
lcd.print(" STM32F103C8T6 ");
}
void loop()
{
// Do nothing here…
}
Re: program modification
Here is an I2C scanner for the second I2C bus.
I have verified its function on my STM32F103 using I2C #2.
I have verified its function on my STM32F103 using I2C #2.
Code: Select all
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
// TwoWire Wire2(SDA2, SCL2);
TwoWire Wire2(PB11, PB10);
void setup()
{
Wire2.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire2.beginTransmission(address);
error = Wire2.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}
Re: program modification
When I upload this code the Green LED on board is flashing and nothing on serial monitor. What are yours scanning results of pins PB10 and PB11?
Re: program modification
I had a 128x64 OLED connected to PB10 / PB11 and the scanner displayed:
I2C device found at address 0x3C
If your STM32F103 board has a green LED, it is not the same one I have and that may explain your results.
I2C device found at address 0x3C
If your STM32F103 board has a green LED, it is not the same one I have and that may explain your results.
Re: program modification
if you happened to have a logic analyzer it may help after all to look at the signals
i wrote one and posted it here, on the repository,
https://github.com/ag88/SumpSTM32F401cc
this one runs on stm32f401cc black pill board. i think it is quite possible to port it to stm32f103
this logic analyzer is made based on stm32f401cc as it has more sram compared to stm32f103c{8,b} which has only 20k
on the repository web i've also given references to other logic analyzers. including some that runs on stm32f103
then if you have the time to wait and do not want to bother to using one based on these 'dev boards'
there are many on ebay and the likes
https://www.aliexpress.com/wholesale?Ca ... c+analyzer
they are mostly higher speeds but i'd guess not very different from using a stm32 pill board for that purpose
on some boards such as the maple mini 'clones' the pins are not labelled based on the stm32 gpio port tags.
but rather numbered off numerically. it may help to use a voltmeter or a led to verify the pins are after all at that port
that is quite easy to do with a digitalWrite(pin, HIGH) sketch
i wrote one and posted it here, on the repository,
https://github.com/ag88/SumpSTM32F401cc
this one runs on stm32f401cc black pill board. i think it is quite possible to port it to stm32f103
this logic analyzer is made based on stm32f401cc as it has more sram compared to stm32f103c{8,b} which has only 20k
on the repository web i've also given references to other logic analyzers. including some that runs on stm32f103
then if you have the time to wait and do not want to bother to using one based on these 'dev boards'
there are many on ebay and the likes
https://www.aliexpress.com/wholesale?Ca ... c+analyzer
they are mostly higher speeds but i'd guess not very different from using a stm32 pill board for that purpose
on some boards such as the maple mini 'clones' the pins are not labelled based on the stm32 gpio port tags.
but rather numbered off numerically. it may help to use a voltmeter or a led to verify the pins are after all at that port
that is quite easy to do with a digitalWrite(pin, HIGH) sketch
Last edited by ag123 on Thu Jan 28, 2021 7:30 am, edited 1 time in total.
Re: program modification
I am using this board and oscilloscope.
Green LED is on PC13
Which program you are using for testing OLED on pins PB10 and PB11?
my address for pins PB6/7 and PB8/9 is 0x3C - using not modify scanner program.
Green LED is on PC13
Which program you are using for testing OLED on pins PB10 and PB11?
my address for pins PB6/7 and PB8/9 is 0x3C - using not modify scanner program.
Re: program modification
Can you try this program on PB8 and PB9 ? I tis working with my stm32f103 only on PB6 and PB7.
Code: Select all
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
//#if (SSD1306_LCDHEIGHT != 64)
#if (SSD1306_LCDHEIGHT != 32)
///#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
int sensorValue = 0;
int voltage = 0;
const int analogInPin = PA7;
//display.invertDisplay(true); // invert the colours of led display
//display.invertDisplay(false);
//display.drawPixel(10, 10, WHITE);//to highlight a particular pixel
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize I2C addr to 0x3C ( for 128x64 Display )
display.clearDisplay(); // clear the display before starting the program to avoid adafruit splashscreen ( *we can also skip it by modifing header file )
// display.drawBitmap(x-axis position, y-axis position, bitmap data, bitmap width, bitmap height, color)
display.drawPixel(100, 15, WHITE);//to highlight a particular pixel
}
void loop()
{
display.clearDisplay();
display.setTextSize(4);
display.setTextColor(WHITE);
sensorValue = analogRead(analogInPin);
voltage = map(sensorValue, 0, 4096, 0, 3300);
display.setCursor(0, 0);
display.print(voltage);
display.display();
}