nucleo 32-l432kc with mcp23018 Problème IODIR

Post here first, or if you can't find a relevant section!
Post Reply
fana92i
Posts: 3
Joined: Fri Dec 03, 2021 4:50 pm

nucleo 32-l432kc with mcp23018 Problème IODIR

Post by fana92i »

hello everybody :)

I am new user, i hope i am in the good section !

1st - sorry im french so i use google translate to try to explain my problem .. :)

2nd - ENVIRONMENT

/nucleo 32-l432kc
/IDE ARDUINO
/Wire.h
/all Register 0x00
/ADDRS : mcp1 0x20
/ADDRS : mcp2 0x21
/ADDRS : GPOIA 0X12
/ADDRS : GPIOB 0X13

3rd - Project

my new project is to order a mcp23018 with the nucleo 32, to order on each output pin (16i / o).

i use only the Wire Library, and i configure the register himself.

the connection is well established and I have checked the state of my register as well as their state, everything is functional.

I also manage to drive each output one by one on each port A or B of the mcp23018 (OPEN-DRAIN) to start the leds initially.

My Problem is related to the IODIR register, which configures the pins in input or output.

I put 0x00 for output in IODIR but at power-up all the outputs are activated, which causes me a problem.

When I program all the outputs to 0000 000 (open-drain) this activates the outputs, my leds light up no problem, but if I program them to 1111 1111 (off), when the power is turned on it creates a small flash because at rest or without default command the pins are activated.

if I comment out the IODIR register that removes the problem for me but my pins go into input ... :?

I think that there must be in the other registers a configuration to make to remove the problem but I block above.

The mcp is ultimately quite complex I found on the datasheet, a lot of configurable register and I may get lost in it :lol:

Someone have already programmed this mcp23018 on nucleo under IDE ARDUINO?

Thanks for reading me :D :D

http://ww1.microchip.com/downloads/en/d ... 22103a.pdf FOR MCP23018
Last edited by fana92i on Fri Dec 03, 2021 5:43 pm, edited 1 time in total.
fana92i
Posts: 3
Joined: Fri Dec 03, 2021 4:50 pm

Re: nucleo 32-l432kc with mcp23018 Problème IODIR

Post by fana92i »

// I put my code in the setup to avoid the while in the loop to understand my problem
// I am attaching my void() registers configuration in another message




#include <Wire.h>



#define I2C_ADDR1 0x20 // ADDRS MCP 23018 1
#define I2C_ADDR2 0x21 // ADDRS MCP 23018 2


// --- SETTING REGISTER ADDRESES ---

uint8_t IODIRA = 0x00;
uint8_t IODIRB = 0x01;
uint8_t IPOLA = 0x02;
uint8_t IPOLB = 0x03;
uint8_t GPINTENA = 0x04;
uint8_t GPINTENB = 0x05;
uint8_t DEFVALA = 0x06;
uint8_t DEFVALB = 0x07;
uint8_t INTCONA = 0x08;
uint8_t INTCONB = 0x09;
uint8_t IOCONA = 0x0A;
uint8_t IOCONB = 0x0B;
uint8_t GPPUA = 0x0C;
uint8_t GPPUB = 0x0D;
uint8_t INTFA = 0x0E;
uint8_t INTFB = 0x0F;
uint8_t INTCAPA = 0x10;
uint8_t INTCAPB = 0x11;
uint8_t GPIOA_ = 0x12;
uint8_t GPIOB_ = 0x13;
uint8_t GPIOA1_ = 0x12;
uint8_t GPIOB1_ = 0x13;
uint8_t OLATA = 0x14;
uint8_t OLATB = 0x15;


void setup()
{
Wire.setSDA (PA10); // SET PIN NUCLEO PA10 FOR -- SERIAL DATA LINE -- (OR D0)
Wire.setSCL (PA9 ); // SET PIN NUCLEO PA9 FOR -- SERIAL CLOCK LINE -- (OR D1)
Wire.begin (); // INIT COM
Serial.begin(115220); // Serial Monitor
RegisterConfig (); // config of register


Wire.beginTransmission(I2C_ADDR2); // transmit to device MCP 23018 NO 2 ( addrs 0x21 )
Wire.write(GPIOA_); // transmit to register GPIOA MCP 2
Wire.write(0x00); // transmit to register to activate all pin A for mcp 2
Wire.endTransmission(); // stop transmit

Wire.beginTransmission(I2C_ADDR2); // transmit to device MCP 23018 NO 2 ( addrs 0x21 )
Wire.write(GPIOB_); // transmit to register GPIOB MCP 2
Wire.write(0x00); // transmit to register to activate all pin B for mcp 2
Wire.endTransmission(); // stop transmit

Wire.beginTransmission(I2C_ADDR1); // transmit to device MCP 23018 NO 1 ( addrs 0x20 )
Wire.write(GPIOA1_); // transmit to register GPIOA MCP 1
Wire.write(0x00); // transmit to register to activate all pin A for mcp 1
Wire.endTransmission(); // stop transmit

Wire.beginTransmission(I2C_ADDR1); // transmit to device MCP 23018 NO 1 ( addrs 0x20 )
Wire.write(GPIOB1_); // transmit to register GPIOB MCP 1
Wire.write(0x00); // transmit to register to activate all pin A for mcp 1
Wire.endTransmission(); // stop transmit

}

void loop ()
{
//Serial.println(GPIOA_); // DEBUG VEW VALUE GPIOA DECIMAL MODE
//bitClear(GPIOA_,0);
//bitClear(GPIOA_,7);
//bitClear(GPIOB_,1);
//Serial.println(GPIOA_); // DEBUG VEW VALUE GPIOA AFTER CHANGE ONE BITE

/*Wire.beginTransmission(I2C_ADDR2); // transmit to device MCP 23018 NO 2 ( addrs 0x21 )
//Wire.write(0x00);
Wire.write(GPIOA_);
Wire.write(0xFE);
Wire.endTransmission(); // stop transmitting// stop transmitting

Wire.beginTransmission(I2C_ADDR2); // transmit to device MCP 23018 NO 2 ( addrs 0x21 )
//Wire.write(0x00);
Wire.write(GPIOB_);
Wire.write(0xFE);
Wire.endTransmission(); // stop transmitting// stop transmitting*/


//Wire.beginTransmission(I2C_ADDR1); // transmit to device MCP 23018 NO 2 ( addrs 0x20 )
//Wire.write(0x0000);
//Wire.write(GPIOA_);
// Wire.write(GPIOB_); // GPIOB
//Wire.endTransmission(); // stop transmitting


}
Last edited by fana92i on Fri Dec 03, 2021 10:31 pm, edited 3 times in total.
fana92i
Posts: 3
Joined: Fri Dec 03, 2021 4:50 pm

Re: nucleo 32-l432kc with mcp23018 Problème IODIR

Post by fana92i »

void ConfigRegister (uint8_t Addrs,uint8_t Register,uint8_t Config)

{
Wire.beginTransmission(Addrs); // Choose Addrs of mcp 23018
Wire.write(Register); // choose Register ex : iocon
Wire.write(Config); // Choose Configu Register ex : 0x00 for incative
Wire.endTransmission();

}

void RegisterConfig ()
{

//( Adresse MCP 1, REGISTER , CONFIG )
ConfigRegister (I2C_ADDR1,IOCONA, 0x00);
ConfigRegister (I2C_ADDR1,IOCONB, 0x00);
ConfigRegister (I2C_ADDR1,IPOLA, 0x00);
ConfigRegister (I2C_ADDR1,IPOLB, 0x00);
ConfigRegister (I2C_ADDR1,GPINTENA,0x00);
ConfigRegister (I2C_ADDR1,GPINTENB,0x00);
ConfigRegister (I2C_ADDR1,DEFVALA, 0x00);
ConfigRegister (I2C_ADDR1,DEFVALB, 0x00);
ConfigRegister (I2C_ADDR1,INTCONA, 0x00);
ConfigRegister (I2C_ADDR1,INTCONB, 0x00);
ConfigRegister (I2C_ADDR1,GPPUA, 0x00);
ConfigRegister (I2C_ADDR1,GPPUB, 0x00);
ConfigRegister (I2C_ADDR1,INTFA, 0x00);
ConfigRegister (I2C_ADDR1,INTFB, 0x00);
ConfigRegister (I2C_ADDR1,INTCAPA, 0x00);
ConfigRegister (I2C_ADDR1,INTCAPB, 0x00);
ConfigRegister (I2C_ADDR1,OLATA, 0x00);
ConfigRegister (I2C_ADDR1,OLATB, 0x00);
ConfigRegister (I2C_ADDR1,IODIRA, 0x00);
ConfigRegister (I2C_ADDR1,IODIRB, 0x00);




//( Adresse MCP 2 , REGISTER , CONFIG )
ConfigRegister (I2C_ADDR2,IOCONA, 0x00);
ConfigRegister (I2C_ADDR2,IOCONB, 0x00);
ConfigRegister (I2C_ADDR2,IPOLA, 0x00);
ConfigRegister (I2C_ADDR2,IPOLB, 0x00);
ConfigRegister (I2C_ADDR2,GPINTENA,0x00);
ConfigRegister (I2C_ADDR2,GPINTENB,0x00);
ConfigRegister (I2C_ADDR2,DEFVALA, 0x00);
ConfigRegister (I2C_ADDR2,DEFVALB, 0x00);
ConfigRegister (I2C_ADDR2,INTCONA, 0x00);
ConfigRegister (I2C_ADDR2,INTCONB, 0x00);
ConfigRegister (I2C_ADDR2,GPPUA, 0x00);
ConfigRegister (I2C_ADDR2,GPPUB, 0x00);
ConfigRegister (I2C_ADDR2,INTFA, 0x00);
ConfigRegister (I2C_ADDR2,INTFB, 0x00);
ConfigRegister (I2C_ADDR2,INTCAPA, 0x00);
ConfigRegister (I2C_ADDR2,INTCAPB, 0x00);
ConfigRegister (I2C_ADDR2,OLATA, 0x00);
ConfigRegister (I2C_ADDR2,OLATB, 0x00);
ConfigRegister (I2C_ADDR2,IODIRA, 0x00);
ConfigRegister (I2C_ADDR2,IODIRB, 0x00);
}
Post Reply

Return to “General discussion”