Code Monkey home page Code Monkey logo

Comments (10)

uvwxy avatar uvwxy commented on August 26, 2024

My thoughts on this so far:

In I2C.c: sendAddress(uint8_t i2cAddress):
is the third statement actually correct?

	/* Test on EV5 and clear it */
	while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));

	/* Send the Address + Direction */
	I2C->DR = i2cAddress;	// I2C_Send7bitAddress()

	/* Test on EV6 and clear it */
	while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));

Shouldn't we wait here for I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED (in case we want to write)?

Wouldn't this mean we need two check the LSB in i2cAddress to determine the right event to wait for, for this to be correct?

The doc in stm8s_i2c.h states:

    * Then the master has to wait that a slave acknowledges his address.
    * If an acknowledge is sent on the bus, one of the following events will
    * be set:
    *
    *  1) In case of Master Receiver (7-bit addressing):
    *  the I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED event is set.
    *
    *  2) In case of Master Transmitter (7-bit addressing):
    *  the I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED is set

Then in receiveByte

    while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED));
     // TODO: store  I2C->DR in bytebuffer
    // TODO: send 'ack/nack'
    return 0;

...

from sduino.

uvwxy avatar uvwxy commented on August 26, 2024

You can assign this one to me. I just read a single byte from I2C..

from sduino.

uvwxy avatar uvwxy commented on August 26, 2024

I started a complete rewrite of I2C.c / I2C.h, as most of the functionality is handled by stm8s_i2c anyway...

It's work in progress

I am reading the data fields (8 bytes) from a BME280 sensor and print the bytes to the OLED (poor man's debugging)...

I can create a pull request once you are happy with the changes. I'm not 100% happy yet, as there are possible lockups if slaves don't reply correctly, or are not answering at all 😱

from sduino.

tenbaht avatar tenbaht commented on August 26, 2024

Sounds good, thank you!

stm8s_i2c is part of the SPL. It is used sometimes for historic reasons, but my goal is to remove all dependencies and include it only as an optional library that could be used, if that seems to be useful for a project (because it might be ported to STM32 later).

For the core files (wiring.c, wiring_analog.c, HardwareSerial.c) I use a compiler flag USE_SPL to separate the parts requiring SPL and the stand-alone parts from each other. I think it would be helpful if you do something similar for i2c.

In general most spl function just test for one flag or do a simple register access. In most cases that is not really useful and can easily be replaced. But there are some exceptions. The uart initialization is a good example. It does useful calculations and it couldn't be done much simpler, so it might be more useful to avoid duplicating code and just stay with the spl function.

from sduino.

tenbaht avatar tenbaht commented on August 26, 2024

I tried to assign this one to you but it doesn't accept your username. Don't know why.

from sduino.

uvwxy avatar uvwxy commented on August 26, 2024

Good point. I will introduce the USE_SPL flag into the I2C library.

from sduino.

uvwxy avatar uvwxy commented on August 26, 2024

I tried to assign this one to you but it doesn't accept your username. Don't know why.

uvwxy ? awww 😔

For the core files (wiring.c, wiring_analog.c, HardwareSerial.c) I use a compiler flag USE_SPL to separate the parts requiring SPL and the stand-alone parts from each other. I think it would be helpful if you do something similar for i2c.

Am I doing this right?

I'm not considering this as stable, but it works for me 🤓

from sduino.

uvwxy avatar uvwxy commented on August 26, 2024

I had to play around with the function names as I was getting warnings about duplicate global symbols. Do I have to remove them from the .lib files? Either way, I couldn't figure out how to exclude the stm8s_i2c.(c|h) as done with the uart(2|3|4) files...

Maybe you can help me out on this one?

from sduino.

uvwxy avatar uvwxy commented on August 26, 2024

I added an example for ADXL345, here.

Unfortunately I have not been very successful with the I2C on the stm8s103. I can read a few bytes here and but it is way too buggy to be useful. Also, writing to I2C crashes here and there so I'm not sure if I made things worse on my branch. 😅

from sduino.

aryeguetta avatar aryeguetta commented on August 26, 2024

Hi, I am new and I would like to try STM8S boards as well - already got me a couple to start with - the basic cheap ones - 2 under 1 USD :)
I have set up the JSON and installed the boards from the board manager - I have also tried the manual way but with no luck at all.
I have issues that every time I upload a sketch I get a warning about /tmp folder that needs to be created for the bash - I do have it and at the end, it uses it - I wonder why I am getting this error.
bash.exe: warning: could not find /tmp, please create!
I would be happy to learn more and help if needed :)
I am using Windows 8.1 and already have my ST-LINKV2 connected and working
I was able to upload only the blink sketch and I do want to be able to do more.

Main problem that I had is that I can not try any of the examples - it always says that I am missing something -
in Servo:
\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.3.3\libraries\Servo\src\stm8\Servo.c:24:22: fatal error: irqtable.h: No such file or directory
in oled-mini:
\AppData\Local\Arduino15\packages\sduino\hardware\stm8\0.3.3\libraries\I2C\I2C.c:398: error 20: Undefined identifier 'TWDR'

I wish I could use them for a small projects that I was hopeing to.
Please assist.
Thanks

from sduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.