Go Down

Topic: ´twi_writeTo' was not declared in this scope on Uno wifi rev2 (Read 337 times) previous topic - next topic

Scoobie

Hi all,

i have a Uno wifi rev2 which is fully updated (up to 5-6-2019 -1.8.1 and 1.6.23).

I installed a Multiplexer and am trying to get it to work. As i am a bit of a NOOB, i copied the test code form the site and tried to verify and compile it. I get an error :´twi_writeTo' was not declared in this scope

The code:
Code: [Select]
    /**
     * TCA9548 I2CScanner.pde -- I2C bus scanner for Arduino
     *
     * Based on code c. 2009, Tod E. Kurt, http://todbot.com/blog/
     *
     */
     
    #include "Wire.h"
    extern "C" {
    #include "utility/twi.h"  // from Wire library, so we can do bus scanning
    }
     
    #define TCAADDR 0x70
     
    void tcaselect(uint8_t i) {
      if (i > 7) return;
     
      Wire.beginTransmission(TCAADDR);
      Wire.write(1 << i);
      Wire.endTransmission(); 
    }
     
     
    // standard Arduino setup()
    void setup()
    {
        while (!Serial);
        delay(1000);
     
        Wire.begin();
       
        Serial.begin(115200);
        Serial.println("\nTCAScanner ready!");
       
        for (uint8_t t=0; t<8; t++) {
          tcaselect(t);
          Serial.print("TCA Port #"); Serial.println(t);
     
          for (uint8_t addr = 0; addr<=127; addr++) {
            if (addr == TCAADDR) continue;
         
            uint8_t data;
            if (! twi_writeTo(addr, &data, 0, 1, 1)) {
               Serial.print("Found I2C 0x");  Serial.println(addr,HEX);
            }
          }
        }
        Serial.println("\ndone");
    }
     
    void loop()
    {
    }



I have read a post on this forum where it was said that this code is a kind of bypass and it was suggested that one would use idrect coding ( :o  i am clueless with these terms).

I hope someone can help me out with a solution so that i can get on tinkering :)

Many thanks for Any help!!

Scoobs

DrAzzy

That code is not compatible with the Wire library for the Uno Wifi Rev. 2.

That code as written is only compatible with classic AVR (not megaAVR like the atmega4809 used in the Uno Wifi Rev. 2) boards, and not even ones that don't have hardware I2C (for example, ATTiny, which use the USI, or in some cases need a software implementation - even though with my ATTinyCore, there's a Wire library that presents the same interface).

Really, that code demonstrates terrible coding practice - you use the public API of a library, you don't reach into the guts of a library and pull out an internally used function. It's no surprise that it broke the moment you used a board that wasn't what the author of the code had in mind. He wrote that code a DECADE ago, too, it's ancient.

I'm pretty sure people have written I2C bus scanners since that don't require using the utility functions directly (maybe that was necessary with the version of the Wire library available 10 years ago, though).... Modifying one of those to use the multiplexer shouldn't be that hard.

(Also, why do you need an I2C multiplexer? You know you can put multiple devices on the same I2C bus, as long as they have different addresses, right? That strikes me as a rather unusual part to be working with, especially as a relative novice - unless you need to use multiples of the same I2C device, and that device doesn't have a way to set the address, you probably shouldn't be using an I2C multiplexer)
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Scoobie

Thank you for replying. As you stated.. i will look for a busscanner that's not written in Fred Flintstone's time :)

I am trying to use three of the same sensors (humid/temp) that have identical fixed adresses. A multiplexer should fix my troubles.

I am going to look for my new bus scanner.

Many thanks!!

DrAzzy

Why even use a bus scanner, if you know the addresses of everything you're using?
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Go Up