# I2C Bus write return -1

**URL:** <https://forum.sierrawireless.com/t/i2c-bus-write-return-1/2181>\
**Category:** General wireless topics\
**Created:** [May 19, 2008, 6:23am UTC](https://forum.sierrawireless.com/t/i2c-bus-write-return-1/2181 "2008-05-19T06:23:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkat](https://avatars.discourse-cdn.com/v4/letter/v/4491bb/32.png) [@venkat](https://forum.sierrawireless.com/u/venkat)\
**Post date:** [May 19, 2008, 6:23am UTC](https://forum.sierrawireless.com/t/i2c-bus-write-return-1/2181/1 "2008-05-19T06:23:05Z")

</div>

Hi All,

I am trying to work on i2c bus of wavecom (Q24 Plus) with PCA9502 I/O expander ( [nxp.com/acrobat\_download/dat … 9502\_3.pdf](http://www.nxp.com/acrobat_download/datasheets/PCA9502_3.pdf) ) which has i2c/spi inerface.

Bus Enable always sucuss and bus write function always return -1 (BUS\_MODE\_UNKNOWN\_TYPE)

Could any one help to find out the problem.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![trthaithong](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@trthaithong](https://forum.sierrawireless.com/u/trthaithong)\
**Post date:** [May 21, 2008, 8:56am UTC](https://forum.sierrawireless.com/t/i2c-bus-write-return-1/2181/2 "2008-05-21T08:56:45Z")

</div>

Hi venkat,  
Can you show the code? All i2c parameters config right?  
ttt

---

<div class="post-metadata">

**Author:** ![venkat](https://avatars.discourse-cdn.com/v4/letter/v/4491bb/32.png) [@venkat](https://forum.sierrawireless.com/u/venkat)\
**Post date:** [May 22, 2008, 6:57am UTC](https://forum.sierrawireless.com/t/i2c-bus-write-return-1/2181/3 "2008-05-22T06:57:17Z")

</div>

Hi trthaithong,

I here by post my code as on your request.

```auto
void iic_Init( u8 id )
{
    adl_atSendResponse(ADL_AT_UNS,"\r\n I'm in iic_Init\r\n");
    
    /* i2c bus initialization */
    // slave address 0x92
    iic_BusHandle = adl_busSubscribe( ADL_BUS_TYPE_I2C_HARD|0x49, ADL_BUS_I2C_HARD_CLK_STD );

   if( iic_BusHandle == ADL_RET_ERR_PARAM )
   {
       adl_atSendResponse(ADL_AT_UNS,"\r\n ERROR : ONE OF THE PARAMETER HAS INCORRECT VALUE \r\n" );
   }
  else if( iic_BusHandle == ADL_RET_ERR_ALREADY_SUBSCRIBED )
  {
      adl_atSendResponse(ADL_AT_UNS,"\r\n ERROR : IIC BUS ALREADY SUBSCRIBED \r\n" ); 
  }
  else if( iic_BusHandle >= 0 )
   {
      adl_atSendResponse(ADL_AT_UNS,"\r\n IIC BUS ENABLE SUCCESS\r\n" );
      pca_Config( 1 );
   }
   else
   {
     adl_atSendResponse(ADL_AT_UNS,"\r\n IIC BUS ENABLE FAIL\r\n" );
   }	
}

void pca_Config( u8 id )
{
    s8 iic_BusWrHandle;
    char tempBuf[100];
    
    // IOControl register address 0x0E
    iic_BusWrHandle = adl_busWrite( (u8) iic_BusHandle, (adl_busAccess_t *) NULL, (u32) Data_Len, (void *) 0x07 );
    
    // iic_BusWrHandle = adl_busWrite( (u8) iic_BusHandle, (adl_busAccess_t *) NULL, (u32) Data_Len, (void *) 0x0E );

    if( iic_BusWrHandle == ADL_RET_ERR_UNKNOWN_HDL )
    {
        adl_atSendResponse(ADL_AT_UNS,"\r\n ERROR : IIC HANDLE PROVIDED AS UNKNOWN \r\n");
    }
    else if( iic_BusWrHandle == ADL_RET_ERR_PARAM )
    {
        adl_atSendResponse(ADL_AT_UNS,"\r\n ERROE : PARAMETER HAS INCORRECT VALUE \r\n");
    }
    else if( iic_BusWrHandle == OK )
    {
       adl_atSendResponse(ADL_AT_UNS,"\r\n SUCCESS : IIC BUS WRITE SUCCESS \r\n");     
    }
    else
    {
        sprintf( tempBuf, "\r\n ERROR NUMBER : %d \r\n",iic_BusWrHandle );
        adl_atSendResponse(ADL_AT_UNS,"\r\n ERROR : IIC BUS WRITE UNKNOWN ERROR \r\n");
        adl_atSendResponse(ADL_AT_UNS,tempBuf);
    }
}
```

## For above code, i had the messages as below

I’m in iic\_Init

IIC BUS ENABLE SUCCESS

ERROR : IIC BUS WRITE UNKNOWN ERROR

## ERROR NUMBER : -1

Please let me know any problem with my config code…

Thanks & regards

---

<div class="post-metadata">

**Author:** ![trthaithong](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@trthaithong](https://forum.sierrawireless.com/u/trthaithong)\
**Post date:** [June 3, 2008, 9:16am UTC](https://forum.sierrawireless.com/t/i2c-bus-write-return-1/2181/4 "2008-06-03T09:16:58Z")

</div>

Hi venkat,

1. For this line:  
iic\_BusWrHandle = adl\_busWrite( (u8) iic\_BusHandle, (adl\_busAccess\_t \*) NULL, (u32) Data\_Len, (void \*) 0x07 );  
0x07 would be treated as memory address  
If you wanted to write one byte (assume you already set “Data\_Len” to 1)  
Data\_Byte = 0x07;  
iic\_BusWrHandle = adl\_busWrite( (u8) iic\_BusHandle, (adl\_busAccess\_t \*) NULL, (u32) Data\_Len, (void \*) &Data\_Byte );

2. But this does not seem to correspond to the error -1, which is “BUS\_MODE\_UNKNOWN\_TYPE” – are you using a very old version of Open AT® that does not have I2C hard?  
ttt

---

<div class="post-metadata">

**Author:** ![venkat](https://avatars.discourse-cdn.com/v4/letter/v/4491bb/32.png) [@venkat](https://forum.sierrawireless.com/u/venkat)\
**Post date:** [June 4, 2008, 10:04am UTC](https://forum.sierrawireless.com/t/i2c-bus-write-return-1/2181/5 "2008-06-04T10:04:06Z")

</div>

Hi trthaithong,

Currently i am using open AT OS v03.12 and open AT software tool v03.13.

1. I don’t know weather my OPEN AT version supporting i2c hard bus or not?

2. Which Open AT version support i2c hard bus?

Thanks&Regards,  
venkat

---

<div class="post-metadata">

**Author:** ![trthaithong](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@trthaithong](https://forum.sierrawireless.com/u/trthaithong)\
**Post date:** [June 6, 2008, 3:28am UTC](https://forum.sierrawireless.com/t/i2c-bus-write-return-1/2181/6 "2008-06-06T03:28:46Z")

</div>

Hi venkat,  
You are already dev on the OS have i2c hard (OS v3.12). It is because of another reason.  
ttt

---

<div class="post-metadata">

**Author:** ![venkat](https://avatars.discourse-cdn.com/v4/letter/v/4491bb/32.png) [@venkat](https://forum.sierrawireless.com/u/venkat)\
**Post date:** [June 6, 2008, 7:29am UTC](https://forum.sierrawireless.com/t/i2c-bus-write-return-1/2181/7 "2008-06-06T07:29:42Z")

</div>

Hi trthaithong,

Thanks for ur reply.

I have tested my hardware by use of scope. There SDA and SCL lines seems always  
high. There no pluses observed!!! 😠

Also adl\_busSubscribe() function always success, i mean if i laod the slave address as 0x01,0x02… its success. How? ❓

I am excepting a document about i2c bus of wavecom.

Could you please help to find out this problem.

Thanks & Regards,  
Venkat

---

<div class="post-metadata">

**Author:** ![Madouc](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Madouc](https://forum.sierrawireless.com/u/Madouc)\
**Post date:** [September 8, 2008, 3:34pm UTC](https://forum.sierrawireless.com/t/i2c-bus-write-return-1/2181/8 "2008-09-08T15:34:08Z")

</div>

I suppose BusSubscribe only allocates the memory and initialises it with the provided settings.  
bus\_write/read commands (and their variations) are the only commands that actually output to the bus.

The only way busSubscribe would fail would be if it can’t allocate the resources it needs.
