Problem getting I2C port 1 and 5 working on MOD54415

Discussion to talk about software related topics only.
User avatar
perkalkyl
Posts: 5
Joined: Fri Oct 30, 2020 5:50 am

Problem getting I2C port 1 and 5 working on MOD54415

Post by perkalkyl »

Hi!
I'm a newbee to the Netburner environment, so maybe this is a super easy thing, but I can't get I2C ports other than 0 working.
Port 0 works fine. But when I change to port 1 or 5, I can't get it to work.
I am using MOD54415 on MOD-DEV-70CR.
Trying Port 1, the id-scan goes super-slow, and when finished, finds a bunch of (non-existing) addresses, except the one I have connected.
Trying Port 5, the scan finds ONLY my connected device (not the actual address on the module), and when I try to send data to it, it crashes.

I am using the IC2-AddressScan code as template. So using MultiChannel_I2CInit, MultiChannel_I2CStart etc.

Also, maybe I misunderstand the concept here, but no matter what address I set in the MultiChannel_I2CInit call, the port always shows up as address 0x51 (7 bit). I would think that it would show up as the address used while initiating it?

To be clear, the ONLY thing I change when trying the other port numbers is the value of I2C_MODULE_NUM. Like

#define I2C_MODULE_NUM 5
..
..
const uint8_t slaveAddr = 0x08; // Address of the NetBurner I2C peripheral
MultiChannel_I2CInit ( I2C_MODULE_NUM, slaveAddr );


Best regards
Per
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Problem getting I2C port 1 and 5 working on MOD54415

Post by TomNB »

I2C is open drain, meaning you have to have pullups on the signals. I2C0 is used on the mod-dev-70 for the RTC, so there 4.7k pullups. So technically you would need pullups on the other channels, but that is not the biggest problem going on. You want to make sure to check the MOD-DEV-70 schematic (located in \nburn\docs\Platform\Schematics to see what else those signals are connected to. In the case of I2C5, the signals are connected to UART1 circuitry, so you can't use it as I2C on the MOD-DEV-70, but you could certainly use it on any board you design as long as you take care of the pullup resistors. It doesn't look like anything is connected to I2C1, so you should be able to use that with proper pullups added.
User avatar
perkalkyl
Posts: 5
Joined: Fri Oct 30, 2020 5:50 am

Re: Problem getting I2C port 1 and 5 working on MOD54415

Post by perkalkyl »

Ok cool. I thought about the MOD-DEV schematics and possible interference last night. The item connected to the unit actually has 10K pull-ups already, but I'll try with adding additional 4.7K pullups.

And what about the adressing? Shouldn't the address I initialize the I2C with also be the address it shows up as in the chain?

And thank you for super-fast reply!
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Problem getting I2C port 1 and 5 working on MOD54415

Post by pbreed »

You may also need to assign the pin functions...
#include <pins.h>

J2[21],function(PINJ2_21_I2C5_SDA );
J2[22],function(PINJ2_22_I2C5_SCL );
User avatar
perkalkyl
Posts: 5
Joined: Fri Oct 30, 2020 5:50 am

Re: Problem getting I2C port 1 and 5 working on MOD54415

Post by perkalkyl »

pbreed, I tried to add those lines (but changed to J2[41],function(PINJ2_41_I2C1_SDA ); ) but i get a compiler error.

#include <predef.h>
#include <string.h>
#include <stdio.h>
#include <nbrtos.h>
#include <http.h>
#include <init.h>
#include <tcpserver.h>
#include <ctype.h>
#include <iosys.h>
#include <serial.h>
#include <basictypes.h>
#include <multichanneli2c.h>
#include <pins.h>
#include <NetworkDebug.h>

const char * AppName="RRMain";

void UserMain(void * pd)
{
init();
WaitForActiveNetwork(TICKS_PER_SECOND * 5); // Wait up to 5 seconds for active network activity
InitializeNetworkGDB_and_Wait();

J2[41],function(PINJ2_41_I2C1_SDA );
J2[44],function(PINJ2_44_I2C1_SCL );

../src/main.cpp:29:9: error: 'function' was not declared in this scope
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Problem getting I2C port 1 and 5 working on MOD54415

Post by pbreed »

Sorry typo and copy and paste error on my part..

Should be . not ,


J2[41].function(PINJ2_41_I2C1_SDA);
J2[44].function(PINJ2_44_I2C1_SCL );
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Problem getting I2C port 1 and 5 working on MOD54415

Post by pbreed »

Also to see what is possible...
IE the various values of:
PINJ2_44_I2C1_SCL etc....

2.X tools
nburn\mod5441x\include\pinconstant.h

3.X tools:
nburn\platform\mod5441x\include\pinconstant.h
User avatar
perkalkyl
Posts: 5
Joined: Fri Oct 30, 2020 5:50 am

Re: Problem getting I2C port 1 and 5 working on MOD54415

Post by perkalkyl »

Ok great.

I've been living my life in C#, Javascript and css in Visual Studio for the past 15 years, so my C++ is rusty to put it mildly. :-D

I am truly grateful for the fast response and help you give @pbreed.
User avatar
perkalkyl
Posts: 5
Joined: Fri Oct 30, 2020 5:50 am

Re: Problem getting I2C port 1 and 5 working on MOD54415

Post by perkalkyl »

Ok, so now I have constructed a PCB to get rid of all possible interference from the Dev board.
Unfortunately the result is the same.
I2C 0 works fine. No problem there. It find the peripherals even without pullup's.
I2C 1 (pin 41 & 44) on the other hand has the same behavior as before. It lists a bunch (50 or so) of addresses (that obviously doesn't exist) in a rate of about 2 per second. When I then try to send data to the address of the existing peripheral (an LCD screen), I get a trap dump:

Leading=BA5EBA11
SwapOutA7=00000000
SwapOutTCB=00000000
SwapInA7=00000000
SwapInTCB=00000000
nPrioOfCurTask=00000033
nPrioOfHighReady =00000033
Trailing=BA5EBA11

-------------------Trap information-----------------------------
Exception Frame/A7 =400ED398
Trap Vector =
SwapOutA7=00000000
SwapOutTCB=00000000
SwapInA7=00000000
SwapInTCB=00000000
OSISRLevel32 =00002000

Debug interupt (12)
Format =04
Status register SR =2000
Fault Status =00
Faulted PC =40050100

-------------------Register information-------------------------
A0=00000000 A1=400ED889 A2=400ED45C A3=000000A3
A4=000000A4 A5=000000A5 A6=400ED3A0 A7=400ED398
D0=00000000 D1=00000020 D2=00000000 D3=00000008
D4=00000000 D5=00000008 D6=00000000 D7=00000040
SR=2000 PC=40050100
-------------------RTOS information-----------------------------
The OSTCBCur current task control block = 400F19B0
This looks like a valid TCB
The current running task is:
-------------------Task information-----------------------------
Task | State |Wait| Call Stack
Idle#3F|Ready | |4003A582,40039CD8,0
Main#32|Timer |0008|4003A30A,40016EF8,40009208,40009D60,40039CD8,
Enet#26|Fifo |0025|4003A30A,40017536,40025EC8,40051AC2,40039CD8,
Config Server#2C|Semaphore |00C4|4003A30A,400173A8,4000A6AA,40044CDC,4000F9C4,
TcpServerInit#33|Running | |40050100,40050AAE,40036DE2,40036EDC,4000930C,40
009340,

-------------------End of Trap Diagnostics----------------------


My main code is:

Code: Select all

#include <predef.h>
#include <string.h>
#include <stdio.h>
#include <nbrtos.h>
#include <http.h>
#include <init.h>
#include <tcpserver.h>
#include <ctype.h>
#include <iosys.h>
#include <NetworkDebug.h>

const char * AppName="RRMain";

void UserMain(void * pd)
{
    init();
    WaitForActiveNetwork(TICKS_PER_SECOND * 5);   // Wait up to 5 seconds for active network activity 
    InitializeNetworkGDB_and_Wait();
    iprintf("Application %s started\n",AppName );

    lcdInit();

    OSSimpleTaskCreatewName(MyTCPServer, (MAIN_PRIO + 1), "TcpServerInit");
    const char* test = "LCDT";

    int ticks = 0;
    while (1)
    {
        OSTimeDly(TICKS_PER_SECOND);
        ticks++;
        if(ticks == 3)
        {
            iprintf("Tick 3 OK!\n");
        }
    }
}
And the LCD init code:

Code: Select all

..
#include <multichanneli2c.h>
#include <pinconstant.h>
#include <pins.h>

#define I2C_MODULE_NUM      1   // Which I2C module to use, default is I2C0
#define I2C_BUS_SPEED  (100000)     // bus speed of 100kHz

void lcdInit()
{
	J2[41].function(PINJ2_41_I2C1_SDA );
	J2[44].function(PINJ2_44_I2C1_SCL );

    const uint8_t slaveAddr = 0x08;         // Address of the NetBurner I2C peripheral
    iprintf("Initializing address: 0x%02X ... ", slaveAddr);

    MultiChannel_I2CInit ( I2C_MODULE_NUM, slaveAddr );
    iprintf("Complete\r\n");

    int numResponses = scanAddressesI2C();
    iprintf("%d addresses responded\r\n", numResponses);

}
Can it be the slave address I'm using? Still haven't understood what that address actually does..
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Problem getting I2C port 1 and 5 working on MOD54415

Post by pbreed »

I2C can me a multimaster bus... the salve addres sis the address I2C would answer to if it was not the master...
So no that is not likely your issue...

If I had to guess I'd say uart1 was still running as a uart...
I'm on the road so I can't run a hardware experiment right now..
Post Reply