cancel
Showing results for 
Search instead for 
Did you mean: 

connecting MCP23017 extender to STM32F4 DISCO communication/testing

oucar.1
Associate II

Hello!

I am trying to connect 8 mcp23017 gpio extenders daisy chained to stm32 but I am having difficulty testing the validity of the ports. I configured the extender and set up the pins to be output pins but when I send the data to write active high to all the ports of the extender, I get no output... what I might be missing here? Is there anything I am fundamentally doing wrong? The extender I am testing the ports with the code below has address 0 (and the base address is 0x20) I would appreciate any kind of help/tips! I included my code below:

thank you!

uint16_t devAddr = 0x80; //addr for the first mcp23017 device opcode

 //register addresses (memAddress) in mcp23017

 uint16_t configMem = 0x05; // addr for the IOCONFIG register in the device (set up the bank)

 uint16_t ioDirAMem = 0x00; //set up the direction of the port A pins on mcp23017

 uint16_t ioDirBMem = 0x10; //set up the direction of the port B pins on mcp23017

 uint16_t gpioB = 0x19; //GPIOB register to be written in order to send data to mcp23017

 //size of internal mem address is 1 byte so (I2C_MEMADD_SIZE_8BIT)

 //data to be sent

 uint8_t dataConfig = 0xE2; //input as &data to the function to give the pointer

 uint8_t dataIODIR = 0x00 ; //set all pins as output

 uint8_t dataSent = 0xFF; // data to send to turn on the ports (all 1)

 HAL_I2C_Mem_Write(&hi2c1, devAddr, configMem, I2C_MEMADD_SIZE_8BIT, &dataConfig, 1, 1000); //configure the registers - bank 0/1 (0x05 - iocon)

 HAL_I2C_Mem_Write(&hi2c1, devAddr, ioDirBMem, I2C_MEMADD_SIZE_8BIT, &dataIODIR, 1, 1000); // input output config (0x00 (port A) - 0x10 (port B))

 HAL_I2C_Mem_Write(&hi2c1, devAddr, gpioB, I2C_MEMADD_SIZE_8BIT, &dataSent, 1, 1000); // write to the port B of the third mcp23017 (send active high to 0x19 (GPIOB for bank1)

5 REPLIES 5

> daisy chained

How? I2C is a bus, you should put all ICs in parallel.

Observe waveforms on the I2C lines using oscilloscope/LA.

JW

oucar.1
Associate II

yes - sorry they are in parallel (I made a mistake with my explanation) but I can't even work with one slave right now... am I sending the signals wrong from what you can see? should I be doing something else to configure the devices?

update: the error is caused by this line specifically:

~code from the driver:

/* Send Slave Address and Memory Address */

  if (I2C_RequestMemoryWrite(hi2c, DevAddress, MemAddress, MemAddSize, Timeout, tickstart) != HAL_OK)

  {

   return HAL_ERROR;

  }

so it's not even communicating properly as a slave. my set-up Is very similar to this one below (I only have one led hooked up to one of the three mcp extenders I have... I don't think it's the connections - I think I am not sending the signals properly/configuring things the right way. I am very new to stm32 so thank you for still helping me out!


_legacyfs_online_stmicro_images_0693W00000dJuMvQAK.png
_legacyfs_online_stmicro_images_0693W00000dJuMqQAK.png
_legacyfs_online_stmicro_images_0693W00000dJuMlQAK.png

Observe waveforms on the I2C lines using oscilloscope/LA.

I2C master can be also relatively easily bit-banged.

JW