Menu

I2C on Atmega328

Jasmine
2017-03-07
2023-03-03
  • Jasmine

    Jasmine - 2017-03-07

    Hello,
    I'd like to use an I2C communication protocol on an Atmega328 with FF. For this purpose I loaded the file i2c-base-avr.txt to the chip. I succeeded to initialize the I2C bus and adress the slave device either for reading or writing, but for some reasons it's not possible to exchange bytes using the i2c.c! command. Are there other words required for the I2C communication? What baudrate is recommended for I2C?
    Additionally we have the problem, that after executing some commands (e.g. i2c.ping?), FF cannot be operated any more probably because it is waiting for something.
    How could we improve the I2C communication?
    Thanks for your support.

     
  • Mikael Nordman

    Mikael Nordman - 2017-03-08

    Hi,
    I added watchdog functionality to the Atmega code.
    With 7 WD+ , the watchdog will timeout in 2 seconds and reset the chip.
    By calling PAUSE or CWD in the loops you can kick the dog and prevent the watchdog reset.
    Since the I2C words do not kick the dog, a watchdog reset will occur if the I2C hangs.
    After restart of FF, the watchdog is disabled, so you have to enable it yourself if you want to use the watchdog.

     
  • Phil Waller

    Phil Waller - 2023-03-03

    Hi,
    I'm using the latest versions of i2c base and i2c detect but still having issues.
    With nothing connected on the bus I get the following output...

    i2c.init ok<#,ram>
    i2c.detect
    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
    00 : W FlashForth 5 ATmega328 19.11.2022

    This is after adding a CWD in each loop.
    Any advice please?

    Cheers

     
  • Mikael Nordman

    Mikael Nordman - 2023-03-03

    Where did you add CWD ? It must be added to I2C.WAIT. Works for me.

     
  • Phil Waller

    Phil Waller - 2023-03-03

    I added to i2c.detect, will try your suggestion, thanks

     
    • Phil Waller

      Phil Waller - 2023-03-03

      Still not working :-(
      It now does not time out but still does not get past 07 on the 1st line of the table.
      Should I be getting an empty table when nothing is connected to the bus?

      On a fresh install (on arduino nano) I am just adding i2c-base and i2c.detect, Do I need anything else?
      sorry for the noob questions, I am new to forth & i2c

      Cheers

       
      • Phil Waller

        Phil Waller - 2023-03-03

        OK, it works if I have a device attached :-)
        Just seems to hang with nothing on the bus.
        I can carry on now I know the address :-)

         
  • Mikael Nordman

    Mikael Nordman - 2023-03-03

    You need at least the pullup resistors
    on the bus to prevent the hanging.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.