November 23, 2024, 03:50:47 AM

STM32-LCD + MOD-RS485-ISO troubles

Started by bizarre, April 07, 2013, 07:38:35 PM

Previous topic - Next topic

bizarre

Hi, everybody.

I have STM32-LCD and I'm trying make work it with MOD-RS485-ISO on UEXT2.

So, if I understand correctly, i must send command to MOD via I2C to start work and then work with it like RS232?

So I tried such code :

      myLCD_Print("TRY TO I2C1 INIT\n");
      I2C1_Init();

      myLCD_Print("I2C1 INITED\n");

        if(FALSE == I2C1_Open())
        {
        myLCD_Print("I2C1 OPEN FAILED\n");
        }
        else
        {
        myLCD_Print("I2C1 OPEN SUCC\n");
        }

        Int8U Data[4];
        Data[0] = 0x04;
        Data[1] = 0xA0;
        Data[2] = 0x30;
        Data[3] = 0x03;

        myLCD_Print("TRY TO SEND\n");

              if(FALSE == I2C1_DataTransfer(0x48, Data, 4))
              {
            myLCD_Print("RS485 SEND FAILED\n");

                I2C1_Close();
              }
              else
              {
              myLCD_Print("RS485 SEND SUCC\n");
              }


And I have
TRY TO I2C1 INIT
I2C1 INITED
I2C1 OPEN SUCC
TRY TO SEND
RS485 SEND FAILED

Please, tell my what can be wrong?

How can I check that the MOD is working? It has some leds or anything else?

thx

LubOlimex

Hey bizzare,

Try setting the I2C speed lower. More than 100 kHz might cause problems.

Else the data you send with I2C1_DataTransfer() seems correct.

Another thing that might cause problems is that depending on when and how you purchased MOD-RS485-ISO it might have an older firmware. Refer to the documents in this example: https://www.olimex.com/Products/Modules/Interface/MOD-RS485-ISO/resources/Demo_MOD-RS485_PIC26J50s.zip.

Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex

bizarre

thx, I have a speed 100000, I make it 50000 - the same result. So, maybe I have a wrong i2c1 init?

I init it by this func:


void I2C1_Init (void)
{
I2C_InitTypeDef  I2C_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;

  _I2C_NotUsed = TRUE;

  // Enable clock
  I2C_DeInit(I2C1);
 
  generate_scl_toggles(10);
 
  RCC_APB1PeriphClockCmd(  RCC_APB1Periph_I2C1,
                           ENABLE);
  RCC_APB2PeriphClockCmd(  RCC_APB2Periph_GPIOB| RCC_APB2Periph_AFIO,
                           ENABLE);

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_5 | GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  // I2C configuration
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_OwnAddress1 = 0xAA;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_ClockSpeed = I2C1_SPEED;

  // I2C Peripheral Enable
  I2C_Cmd(I2C1, ENABLE);

  // Apply I2C configuration after enabling it
  I2C_Init(I2C1, &I2C_InitStructure);

  // Enable the I2C1 Events Interrupt
  NVIC_InitStructure.NVIC_IRQChannel = I2C1_EV_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = I2C1_INTR_PRIO;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = I2C1_INTR_SUBPRIO;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  // Enable the I2C1 Errors Interrupt
  NVIC_InitStructure.NVIC_IRQChannel = I2C1_ER_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = I2C1_INTR_PRIO;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = I2C1_INTR_SUBPRIO;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  // Enable interrupts from I2C1 module
  I2C_ITConfig(I2C1, I2C_IT_BUF | I2C_IT_EVT | I2C_IT_ERR, ENABLE);
}


The MOD I bought direct from Olimex in the november 2012.

selfbg

#3
Hi bizarre,

If you want to use I2C on UEXT2, shouldn't you use GPIO_Pin_8 and GPIO_Pin_9 instead of GPIO_Pin_5 and GPIO_Pin_6?

bizarre

thx for a reply.

But I have read now STM32-LCD doc and MOD - PINS 5 and 6 are the I2C1 SCL2 and SDA2 pins.

So, there is no solution now, and I don't know what to do with it.

Mr LUB, if I had the MOD with old firmware - it will not work at all, or I can check that it is working?

Has anyone another ideas, maybe simple samples for stm32?

thx

LubOlimex

Hey bizarre,

Did you also try with UEXT1?

The older firmware follows another data packet for software interfacing and there are different addresses and commands. You can check the readme files in this example: https://www.olimex.com/Products/Modules/Interface/MOD-RS485-ISO/resources/Demo_MOD-RS485_PIC26J50s.zip. There is a I2C example in the IAR EW examples for their board with the same processor - it is worth to check it.

Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex

bizarre

thx 4 a reply. I will try UEXT1 tomorrow.

so, I tried another way:


      myLCD_Print("TRY TO I2C1 INIT\n");
      I2C1_Init();

      myLCD_Print("TRY TO I2C1 INITED\n");

        if(FALSE == I2C1_Open())
        {
        myLCD_Print("RS485 OPEN FAILED\n");
        }
        else
        {
        myLCD_Print("RS485 OPEN SUCC\n");
        }

          myLCD_Print("I2C_AcknowledgeConfig\n");
          I2C_AcknowledgeConfig(I2C1, ENABLE);
          myLCD_Print("END I2C_AcknowledgeConfig\n");

          myLCD_Print("I2C_GenerateSTART\n");
          I2C_GenerateSTART(I2C1, ENABLE);
          while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
          myLCD_Print("END I2C_GenerateSTART\n");


so I have

I2C_AcknowledgeConfig
END I2C_AcknowledgeConfig
I2C_GenerateSTART

and then nothing.

I paused debugger and program was in this block:


ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, uint32_t I2C_EVENT)
{
  uint32_t lastevent = 0;
  uint32_t flag1 = 0, flag2 = 0;
  ErrorStatus status = ERROR;

  /* Check the parameters */
  assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  assert_param(IS_I2C_EVENT(I2C_EVENT));

  /* Read the I2Cx status register */
  flag1 = I2Cx->SR1;
  flag2 = I2Cx->SR2;
  flag2 = flag2 << 16;

  /* Get the last event value from I2C status register */
  lastevent = (flag1 | flag2) & FLAG_Mask;

  /* Check whether the last event contains the I2C_EVENT */
  if ((lastevent & I2C_EVENT) == I2C_EVENT)
  {
    /* SUCCESS: last event is equal to I2C_EVENT */
    status = SUCCESS;
  }
  else
  {
    /* ERROR: last event is different from I2C_EVENT */
    status = ERROR;
  }
  /* Return status */
  return status;
}


And I saw that

  flag1 = 0 and flag2 = 0

maybe this is problem? We received 4 days ago RTC MOD from olimex, I tried to connect it to UEXT2 - and get

I2C_AcknowledgeConfig
END I2C_AcknowledgeConfig
I2C_GenerateSTART

any ideas?

thx

bizarre