0
\$\begingroup\$

I am trying to communicate with MAX30205 using STLUX385/STNRG388A. I'm using STM8S standard peripheral libraries to communicate with I2C bus. For STNRG388A device drivers, I'm using STLUX385 drivers provided by ST. I can read/write GPIOs, UART communication successfully. But when i tried the I2C bus communication, it's not working as expected. My main.c code is below, rest of the task is in the stlux_it.c in INTERRUPT_HANDLER(I2C_IRQHandler,19)

void main ( void )
{
    // work with HSI at maximum frequency
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);        
    // enable PLL - Used by the SMED
    CLK_PLLCmd(ENABLE);
    while((CLK->PLLR & CLK_PLLR_LOCKP) == 0);

    // initialize the GPIO registers
    GPIO_Init(GPIO1, GPIO_PIN_6, GPIO_MODE_OUT_PP_HIGH_FAST);
    GPIO_Init(GPIO1, GPIO_PIN_7, GPIO_MODE_OUT_PP_HIGH_FAST);

    I2C_DeInit();
    CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, ENABLE);
    I2C_Cmd(ENABLE);
    I2C_Init(I2C_SPEED, SLAVE_ADDRESS, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT,16);// (CLK_GetClockFreq()/1000000));
    I2C_ITConfig((I2C_IT_TypeDef)(I2C_IT_EVT | I2C_IT_BUF), ENABLE);
    rim();
    /* TXBuffer initialization */
    for (i = 0; i < BUFFERSIZE; i++)
        TxBuffer[i] = i;
    I2C_GenerateSTART(ENABLE);
    while (NumOfBytes);
    while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
    /* Add a delay to be sure that communication is finished */
    Delay(0xFFFF);

    while(1);
}

I have checked the MAX30205 with arduino and it's working fine. Waiting for any positive response. Thanks in advance. Regards

\$\endgroup\$
4
  • \$\begingroup\$ It's not working "as expected"... well how is it working? What the heck is NumOfBytes and how does it change values? \$\endgroup\$
    – vicatcu
    Commented Mar 15, 2020 at 16:03
  • \$\begingroup\$ NumOfBytes = 10, the code is sending 10 bytes in the Buffer on the I2C lines in Master mode. But it get's stuck at while(NumOfBytes). \$\endgroup\$ Commented Mar 15, 2020 at 16:39
  • \$\begingroup\$ where is the code that you believe decrements NumOfBytes down to 0? Also where is NumOfBytes even declared? \$\endgroup\$
    – vicatcu
    Commented Mar 16, 2020 at 22:46
  • 1
    \$\begingroup\$ Thanks for the valuable comments, i got the I2C interface working, it was issue with the Pins(Pin 17, Pin 18) I was using. We need to configure these pins in ADX & ADD registers to be used as I2C lines. \$\endgroup\$ Commented Apr 20, 2020 at 14:32

1 Answer 1

1
\$\begingroup\$

We need to configure STNRG388A registers for using Pin 17(SDA) & Pin 18(SCL) as I2C lines. This can be done using the below code in I2C_Init()

//define SDA, SCL outputs, HiZ, Open drain, Fast
GPIO_Init(GPIO1, GPIO_PIN_6, GPIO_MODE_OUT_PP_HIGH_FAST); // Pin 17
GPIO_Init(GPIO1, GPIO_PIN_7, GPIO_MODE_OUT_PP_HIGH_FAST); // Pin 18
MSC->IDXADD = ((u8)0x13);
MSC->IDXDAT = ((u8)MSC_IOMXP2_SEL_P54 & (u8)0x20);

Below line should be added in stlux385.h

#define MSC_IOMXP2_SEL_P54      ((u8)0x30) /*!< Port2[5:4] I/O multiplexing scheme */
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.