Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stm32duino support #9

Open
pacman1945 opened this issue Jan 23, 2020 · 5 comments
Open

stm32duino support #9

pacman1945 opened this issue Jan 23, 2020 · 5 comments

Comments

@pacman1945
Copy link

I'm trying to use this SoftWire with stm32duino link. The library compiles fine and the example ListDevices.ino is working. However, the read() function seems to be broken on stm32 as it returns incorrect values. Any ideas how to get this library to work with stm32duino?

@stevemarple
Copy link
Owner

At the top of SoftWire.cpp this comment explains a potential problem with interrupts:

// If possible disable interrupts whilst switching pin direction. Sadly
// there is no generic Arduino function to read the current interrupt
// status, only to enable and disable interrupts.  As a result the
// protection against spurious signals on the I2C bus is only available
// for AVR architectures where ATOMIC_BLOCK is defined.

This thread suggests there may be an atomic block implementation for the STM32 that could be used.
However I don't know that interrupts are the cause - what happens if you disable interrupts before read() and enable them afterwards?

@pacman1945
Copy link
Author

I've tried disable interrupts in llRead(), but the problem persisted. I've tested another software I2C library, SWire link. It works fine with stm32duino and didn't disable interrupts. Thus, I believe the problem with SoftWire isn't related to interrupts.

@stevemarple
Copy link
Owner

Did you allocate buffers and pass them into SoftWire using the setTxBuffer() and setRxBuffer() functions? A newly-added example, ReadDS1307 demonstrates this.

@LucasFeliciano21
Copy link

LucasFeliciano21 commented Oct 22, 2020

Hey @stevemarple, I'm also testing your library and I can get it to work for the stm32duino witch is this one Arduino Core Stm32, and not the one that you've published. I'm not sure if @pacman1945 is looking for the SoftWire for the core that you mentioned because it's native and works pretty well.

But returning to the question, I've tested with the code for detecting devices and it detects my device, the problem is, there is no response from the devices when I actually do a transfer to the device, the data coming out is always 0, when I change the library to this one SoftWire from Arduino STM32.

Do you have any idea what that might be?

@iLoveAndyBaker
Copy link

I was just having terrible problems with this library on STM32 (STM32F103C8T6), needing a logic analyzer to ferret out the problem, and also a code problem, which was working fine when using the wire library.

The job was a reverse engineering on some Alibaba Ali Express mystery boards, a port from a SAMD / Arduino Zero to STM, and the schematic was botched, requiring software I2C. Doing this work in Platform.io, with soft input pullups enabled. The chip I'm developing on seems to be a legit STM32F103C8T6, I can confirm the same behavior on clearly counterfeit chips as well. Literally spent 5 weeks banging my head against this problem. I could write registers, but couldn't read them.

This may not be the same problem exactly, but the chip and symptoms are.

This is the change that made it live.

iTwoSea.beginTransmission(DevAddr);
iTwoSea.write(RegAddr);
iTwoSea.endTransmission();
//iTwoSea.endTransmission(false); // Original code - This line screws up soft I2C
iTwoSea.requestFrom(DevAddr, (uint8_t)4);

The SDA line wasn't dropping to switch to receive. Getting rid of (false) fixed it.

image
Not what I asked for...

image
For the win!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants