/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / I2C2 expansion connector woes...

Username:     
Password:     
             

Forum

# 1   2009-05-17 16:48:23 I2C2 expansion connector woes...

logictechs
Member
Registered: 2009-05-07
Posts: 68

I2C2 expansion connector woes...

Hi,

I'm trying to use the I2C2 from available examples in the Ride library directory.  It it not working though.  Here is some of the code used:

enum MENU_code Application_Ini(void)
    {
    // TODO: Write your application initialization function here.
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;   
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);   
GPIO_Write(GPIOA, GPIO_Pin_4);   
Delay(0x7FFFF);
 
  /* Configure I2C2 pins: SCL and SDA */
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7 ;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);   
  I2C_InitTypeDef  I2C_InitStructure;

  /* I2C configuration */
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = I2C_1wirereadaddr;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_ClockSpeed = I2C_Speed;
 
  /* I2C Peripheral Enable */
  I2C_Cmd(I2C2, ENABLE);
  /* Enable I2C2 event interrupt */
    I2C_ITConfig(I2C2, I2C_IT_EVT | I2C_IT_BUF , ENABLE);
  /* Apply I2C configuration after enabling it */
  I2C_Init(I2C2, &I2C_InitStructure);
    /* While the bus is busy */
  while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY));

Delay(0x7FFFF);


DS2482_reset();

int DS2482_reset()
{
   u8 status;
u8 str[4];
   // Device Reset
   //   S AD,0 [A] DRST [A] Sr AD,1 [A] [SS] A\ P
   //  [] indicates from slave
   //  SS status byte to read to verify state

   I2C_GenerateSTART(I2C2, ENABLE);

  /* Send address for write */
  I2C_Send7bitAddress(I2C2,I2C_1wirereadaddr , I2C_Direction_Transmitter);
 
   I2C_SendData(I2C2,CMD_DRST);

   I2C_GenerateSTART(I2C2, ENABLE);
/* Send address for write */
  I2C_Send7bitAddress(I2C2,I2C_1wirereadaddr , I2C_Direction_Receiver);

   status = I2C_ReceiveData(I2C2);
   UTIL_int2str(str,status,2,0);
   I2C_GenerateSTOP(I2C2, ENABLE);
DRAW_DisplayString(0,0,str,2);

   // check for failure due to incorrect read back of status
   return ((status & 0xF7) == 0x10);
}

I keep getting a response of 0x05 displayed.  Using my Logic device, I can see only the DS2482 power up pin getting toggled and SDA line going low shortly after.  Attached a pic of that action.  Please help!  Thanks!http://www.ptp-images.com/mini/rsocs6275f.jpg

Offline

 

# 2   2009-05-17 21:13:56 I2C2 expansion connector woes...

logictechs
Member
Registered: 2009-05-07
Posts: 68

Re: I2C2 expansion connector woes...

Hi,

Wanted to provide another symptom to my problem.  If I change I2C2 to I2C1 and some other posts on here suggest, the SDA line toggles low at the same time as my last post but toggles back high 1.24uS later and stays high.  Any help would be greatly appreciated. Thanks!

Offline

 

# 3   2009-05-17 21:42:36 I2C2 expansion connector woes...

repzak
Member
Registered: 2008-03-05
Posts: 170

Re: I2C2 expansion connector woes...

Hello,

I think your problem can be you are not waiting for the hardware to be finished before you make the next I2C command...

You must wait until the hardware is ready...

I have some old prelim code for an touch sensor i want to give you, be aware there is a lot of commented lines there proberly is not needed, but i think you can se the point with the while loops...

Copy the code to an editor for better view....

Kasper

Code:

unsigned char touch_RD(unsigned char addr,unsigned char count)
{
   unsigned char values[65],i;

  /*----- First transmission Phase -----*/
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
 
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); 
  /* Send I2C2 slave Address for write */
  
  I2C_Send7bitAddress(I2C1, SLAVE_ADDRESS7, I2C_Direction_Transmitter);
  /* Test on I2C2 EV1 and clear it */
  //while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED));  
  /* Test on I2C1 EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); 

  /* Send data */

    /* Send I2C1 data */
    I2C_SendData(I2C1, addr); 

    /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);


     DelayMs(10);

   I2C_GenerateSTART(I2C1, ENABLE);
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); 
  /* Send I2C2 slave Address for write */
  I2C_Send7bitAddress(I2C1, SLAVE_ADDRESS7, I2C_Direction_Receiver);


    /* Test on I2C1 EV8 and clear it */
 //   while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); 

/* Test on EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));



    for(i=0;i<count-1;i++)
    {
    /* Test on I2C2 EV2 and clear it */
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));  
    /* Store received data on I2C2 */
    values[i] = I2C_ReceiveData(I2C1);
    }
  
     /* Disable Acknowledgement */
  I2C_AcknowledgeConfig(I2C1, DISABLE);
    /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);
 
       /* Test on I2C2 EV2 and clear it */
    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));  
    /* Store received data on I2C2 */
    values[++i] = I2C_ReceiveData(I2C1);




  /* Test on I2C2 EV4 and clear it */
//       while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_STOP_DETECTED));



    for(i=0;i<12;i+=2)
    {
    temp = values[i+41];
    temp<<=8;
    temp |=    values[i+40];
    printf("%u--",  temp);
      }
    printf("%u--",  values[4]);    */
      /* Disable Acknowledgement */
     I2C_AcknowledgeConfig(I2C1,ENABLE);
     return  values[4];
}

Offline

 

# 4   2009-05-17 22:49:58 I2C2 expansion connector woes...

logictechs
Member
Registered: 2009-05-07
Posts: 68

Re: I2C2 expansion connector woes...

Hi repzak,

Thanks for the reply, but still stuck.  Started looking in the Circle OS files to see what could be going on and found that the audio device uses the I2C2 label instead of I2C1.  I used that code as a guideline to try but still no luck either.  I've tried disabling Timer2 as suggested in another post but still no go.  Has anyone been able to use the I2C2 labeled external I2C port at all?  Please help!  Thanks!

Offline

 

# 5   2009-05-18 05:54:47 I2C2 expansion connector woes...

repzak
Member
Registered: 2008-03-05
Posts: 170

Re: I2C2 expansion connector woes...

Hmm...

Oki, i have not used my code on the primer2...

If i remember clear, i thnk the 7bit adress must be rotated left 1 bit?... think there is an issue on that?

Kasper

Offline

 

# 6   2009-05-18 14:44:34 I2C2 expansion connector woes...

logictechs
Member
Registered: 2009-05-07
Posts: 68

Re: I2C2 expansion connector woes...

Hi Kasper,

Thanks for the reply.  Shouldn't I still be seeing SDA and SCL action using my Logic analyser as I've displayed in my other post?  SCL never toggles and SDA only toggles once after I power up the DS2482 device.  Thanks!

Offline

 

# 7   2009-05-18 17:31:15 I2C2 expansion connector woes...

Saulis
Member
From: Lithuania
Registered: 2009-04-09
Posts: 34

Re: I2C2 expansion connector woes...

May some issues be covered in this: http://www.st.com/stonline/products/lit … /14732.pdf its stm32F103 errata. search for your case it may be documented.

Offline

 

# 8   2009-12-23 15:08:10 I2C2 expansion connector woes...

godmode
New member
Registered: 2009-12-23
Posts: 3

Re: I2C2 expansion connector woes...

Put this before your I2C configuration:
I2C_DeInit(I2C1);
and you should see the signal on your osciloscope.

Offline

 

# 9   2009-12-23 15:11:05 I2C2 expansion connector woes...

godmode
New member
Registered: 2009-12-23
Posts: 3

Re: I2C2 expansion connector woes...

Beside your should turn-on the clock for GPIO that uses I2C:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

Offline

 

# 10   2009-12-25 17:00:56 I2C2 expansion connector woes...

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: I2C2 expansion connector woes...

Hi,

The I2C1_SDA pin is shared with "FSMC_NADV". We have already talk about this problem at this topic :

http://www.stm32circle.com/forum/viewto … 3543#p3543

Yves

Last edited by yrt (2009-12-25 17:01:26)

Offline

 

Board footer