Hello and help

Post Reply
tjm
Posts: 5
Joined: Sun Sep 24, 2017 9:16 pm

Hello and help

Post by tjm » Sun Sep 24, 2017 9:40 pm

Hi I'm new to programming microcontrollers but did a bit with ESP8266 and decided to try STM.The board I have is STM Smart v2 and Arduino set for Generic STM32F103C. I got blink and a little more advanced version to work and now I'm trying to get i2c to work. I loaded the hardware address scanning example but got no serial output at all. In commenting out various lines it appear that the line error = HWire.endTransmission(); never returns. Currently there is nothing attached to PA6 & 7 so I was expecting a message of no addresses found but nothing.

Any suggestions would be appreciated

Tom

User avatar
RogerClark
Posts: 6911
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Hello and help

Post by RogerClark » Sun Sep 24, 2017 10:05 pm

Welcome...

A few things, seem wrong.

Wire is now Hwire, so you may be using an old version.


Also, yiu say nothing is attached... Does that include pullups... I2C needs pullups even if nothig is connected.

tjm
Posts: 5
Joined: Sun Sep 24, 2017 9:16 pm

Re: Hello and help

Post by tjm » Sun Sep 24, 2017 10:52 pm

Hi Roger
Thanks for the quick reply. Here is the snippet from the end of comments which seem to indicate it should be using Hwire. I downloaded the STM_master zip today in case there were some update.

I am getting an error on the upload but it seems to be related to a missing file
Starting download: [##################################################] finished!
error resetting after download: usb_reset: could not reset device, win error: The system cannot find the file specified.
state(8) = dfuMANIFEST-WAIT-RESET, status(0) = No error condition is present


I thought the STM32F103 had built-in pullups; but no I don't have pullups attached. I'll try to find some 10K resistors and put them in place.
Thanks again
Tom

Code: Select all

// Version 6, August 1, 2015
//    Modified to support HardWire for STM32duino
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>

HardWire HWire(1, I2C_FAST_MODE); // I2c1

void setup() {
//  Serial.begin(115200);  I commented this out but it doesn't seem to make any difference
  HWire.begin();
  Serial.println("\nI2C Scanner");
}


void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");
delay(5000);   // my addition
  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.
 
    HWire.beginTransmission(address);
    error = HWire.endTransmission();
    Serial.print("Error = "); //my addition
    Serial.println(error); //my addition
    if (error == 0) {

User avatar
RogerClark
Posts: 6911
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Hello and help

Post by RogerClark » Sun Sep 24, 2017 11:03 pm

Tom

10k is too high. Even on 5V systems the value is normally 4.7k. On 3.3V systems you should use around 2.7k

Re: You code

I amended your post to put the code in the code tags. Use the </> button, as it makes the code easier to read in the post.


Also. You are still declaring and using HWire, There is no longer a need to do this as Wire is HardWire. (Albeit, it defaults to standard speed mode)

Initially for scanning, I would not run in FAST_MODE, I would get it working at the normal speed and if that works, then try FAST_MODE if your peripheral supports it.

tjm
Posts: 5
Joined: Sun Sep 24, 2017 9:16 pm

Re: Hello and help

Post by tjm » Tue Sep 26, 2017 10:21 pm

HI
Sorry to be so long replying.

I put in the pullup resistors but nothing changed so I moved them and changed the power source (from my pi to the stm) and low and behold it started to work. I then connected my mcp23017 and everything stopped working; so I changed the power source again and now it is all working. When I change the mcp back to the pi and leave the power coming from the stm the pi seems happy but the stm doesn't work if the mcp is powered by the pi or if the mcp isn't powered at all.

Thanks for the help it is much appreciated.

Cheers
Tom

User avatar
RogerClark
Posts: 6911
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Hello and help

Post by RogerClark » Tue Sep 26, 2017 10:50 pm

Tom,

I recommend you hook up a logic analyser to the I2C pins and also look at the supply voltages with a multimeter.

When working with hardware peripherals, some test equipment is almost essential.

Fortunately, digital multimeters are incredibly cheap nowadays and there are also very cheap USB based 8 channel logic analysers (sub $10)

Take a look on eBay or AliExpress or even Amazon for "logic analyser 8 channel 24mhz"

tjm
Posts: 5
Joined: Sun Sep 24, 2017 9:16 pm

Re: Hello and help

Post by tjm » Tue Sep 26, 2017 11:08 pm

Thanks Roger - I have an 8 channel Saleae clone and it is indeed most helpful (but only if anything is actually happening); and my old multi-meter should probably be upgraded and the probes are really awkward with these circuits.

Thanks again - your help is always appreciated

Tom

zmemw16
Posts: 1417
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Hello and help

Post by zmemw16 » Tue Sep 26, 2017 11:11 pm

did a wiki search for Smart, anything longer v2 etc confused it.
http://wiki.stm32duino.com/index.php?ti ... Smart_V2.0
@ahull seems to have posted a summary on it, i2c1 has a 24c02 wired in, so i2c-sniffer should see it.
srp

tjm
Posts: 5
Joined: Sun Sep 24, 2017 9:16 pm

Re: Hello and help

Post by tjm » Tue Sep 26, 2017 11:27 pm

Thanks @zmemw16 - that would explain the 50 & 51 addresses

Tom

User avatar
RogerClark
Posts: 6911
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Hello and help

Post by RogerClark » Tue Sep 26, 2017 11:54 pm

If that board already has a I2C device wired onto its I2C pins, it should already have pullup resistors.

Generally the I2C scanner works and does not hang, but there may be some I2C devices which are not compatible with the way the scanner works.

Re: Using the logic analyser

You should be able to see the pins toggling, and analyse the basics of the I2C protocol to see in which phase its hanging.

Post Reply