I2C library : DS1631

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I2C library : DS1631

1,199 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vthinsel on Thu Mar 03 02:02:36 MST 2011
Hello,

I'm porting my I2C library from AVR to LPC176x. The first device I'm porting is the maxim DS1631ib ( http://pdfserv.maxim-ic.com/en/ds/DS1631-DS1731.pdf )

I have an issue as it doesn't get detected. I'm using the Embedded Artists base board and the following configuration/code:


[LIST]
[*]DS1631 pinout
[/LIST]
1=SDA
2=SCL
3=Tout
4=GND
5=A2
6=A1
7=A0
8=Vdd


[LIST]
[*]Connection to LPCXpresso baseboard (using LPC 1769)
[/LIST]

J5-9  : DS1631 pin 2
J5-10 : DS1631 pin 1
J5-1  : DS1631 pin 4,5,6,7
J5-2  : DS1631 pin 8


[LIST]
[*]I2C init code:
[/LIST]
[FONT=Courier New]static void init_i2c(void)
{
    PINSEL_CFG_Type PinCfg;

    /* Initialize I2C2 pin connect */
    PinCfg.Funcnum = 2;
    PinCfg.Pinnum = 10;
    PinCfg.Portnum = 0;
    PINSEL_ConfigPin(&PinCfg);
    PinCfg.Pinnum = 11;
    PINSEL_ConfigPin(&PinCfg);

    // Initialize I2C peripheral
    I2C_Init(LPC_I2C2, 100000);

    /* Enable I2C1 operation */
    I2C_Cmd(LPC_I2C2, ENABLE);
}[/FONT]


The call to[FONT=Courier New] I2C_MasterTransferData(I2CDEV, &txsetup, I2C_TRANSFER_POLLING)[/FONT]fails
Here is the content of the relevant variables upon calling the function

"I2CDEV" = 0x400a0000   

txsetup    {...}   
    sl_addr7bit    144   
    tx_data    0x10007f7f   
    tx_length    1   
    tx_count    0   
    rx_data    0x00000000   
    rx_length    0   
    rx_count    0   
    retransmissions_max    3   
    retransmissions_count    4   
    status    544   
    callback    0x00000000

Where should I look now ?

Thanks.
0 Kudos
Reply
11 Replies

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vthinsel on Thu Mar 10 02:28:38 MST 2011
Hello,

I have made progress, thanks to your advices:

[FONT=System]I2CWrite result:0 SUCC:1 ERROR:0 =>0
I2CWrite result:1 SUCC:1 ERROR:0 =>1
No DS1631
I2CWrite result:1 SUCC:1 ERROR:0 =>1
I2CWrite result:1 SUCC:1 ERROR:0 =>1
I2CWrite result:1 SUCC:1 ERROR:0 =>1
I2CRead result:1 SUCC:1 ERROR:0 =>1
I2CWrite result:1 SUCC:1 ERROR:0 =>1
I2CWrite result:1 SUCC:1 ERROR:0 =>1
I2CRead result:1 SUCC:1 ERROR:0 =>1
I2CWrite result:1 SUCC:1 ERROR:0 =>1
I2CWrite result:1 SUCC:1 ERROR:0 =>1
I2CRead result:1 SUCC:1 ERROR:0 =>1
DS1631 Config register: 74
     DS1631_CONFIG_1SHOT: 0
     DS1631_CONFIG_R0:    0
     DS1631_CONFIG_R1:    1
     DS1631_CONFIG_POL:   1
     DS1631_CONFIG_DONE:  0
     DS1631_CONFIG_TLF:   0
     DS1631_CONFIG_THF:   1
     DS1631_CONFIG_NVB:   0
I2CWriteRead result:1 SUCC:1 ERROR:0 =>1
I2CWriteRead result:1 SUCC:1 ERROR:0 =>1
     DS1631_TH:           15.0000
I2CWriteRead result:1 SUCC:1 ERROR:0 =>1
I2CWriteRead result:1 SUCC:1 ERROR:0 =>1
     DS1631_TL:           10.0000
I2CWriteRead result:1 SUCC:1 ERROR:0 =>1
DS1631 Temp:19.2500
I2CWriteRead result:1 SUCC:1 ERROR:0 =>1
DS1631 Temp:19.2500
I2CWriteRead result:1 SUCC:1 ERROR:0 =>1
DS1631 Temp:19.3750
I2CWriteRead result:1 SUCC:1 ERROR:0 =>1
DS1631 Temp:19.2500
[/FONT]
I had several issues:

[LIST]
[*]The 7bit address as you pointed out
[*]On the EA base board, an I2C peripheral is already at the default address used by the DS1631 :eek:. So at the beginning I got answers from the dual-uart instead of the DS1631....
[*]The reset message to DS1631 is failing (the first I2CWrite above). I need to check this one more in-depth
[/LIST]
Thanks for your help.
0 Kudos
Reply

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Mar 04 05:58:50 MST 2011
Seems a good idea to change that buffers to arrays (for future use of more than 1 byte).

Don't know what your I2C_M_SETUP_Type struct is, but


Quote:

rxsetup.tx_data = buffer_tx; // Get address to read at writing address



is writing buffer_tx and no address :)
0 Kudos
Reply

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vthinsel on Fri Mar 04 05:18:46 MST 2011
They could be but in this specific case as only one element would be in the array
I'll go back to my C lessons, on the pointer chapter. And try to find some examples.
0 Kudos
Reply

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Mar 04 05:10:51 MST 2011
Not familiar with your software, but shouldn't that buffers be arrays?
0 Kudos
Reply

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vthinsel on Fri Mar 04 04:54:36 MST 2011
It was a pointer.

But I changed it to a plain variable and I have the same:

uint8_t buff_tx;
    uint8_t buff_rx;
    I2C_M_SETUP_Type rxsetup;
    // write the ds1631 configuration byte
    buff_tx = DS1631_CMD_ACCESSCONFIG;

    rxsetup.sl_addr7bit = i2cAddr;
    rxsetup.tx_data = &buff_tx;    // Get address to read at writing address
    rxsetup.tx_length = 1;
    rxsetup.rx_data = &buff_rx;
    rxsetup.rx_length = 1;
    rxsetup.retransmissions_max = 3;
0 Kudos
Reply

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Mar 04 04:18:12 MST 2011
What's buffer_tx? Pointer or field?


Quote:

uint8_t* buffer_tx;
buffer_tx[0] = DS1631_CMD_ACCESSCONFIG;

0 Kudos
Reply

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vthinsel on Fri Mar 04 03:36:47 MST 2011
It was this, indeed. Console happily says:
[FONT=Courier New]DS1631 initialized at address 0x48[/FONT] :)

Now I'm progressing and try to read from the DS6131, unfortunately, I end up in:

[FONT=Courier New]void HardFault_Handler(void)
{
    while(1)
    {
    }
}[/FONT]


Context:

[FONT=Courier New]unsigned char ds1631GetConfig(uint8_t i2cAddr,uint8_t *cfg)
{
    uint8_t* buffer_tx;
    uint8_t* buffer_rx;
    // write the ds1631 configuration byte
    buffer_tx[0] = DS1631_CMD_ACCESSCONFIG;

    I2C_M_SETUP_Type rxsetup;

        rxsetup.sl_addr7bit = i2cAddr;
        rxsetup.tx_data = buffer_tx;    // Get address to read at writing address
        rxsetup.tx_length = 1;
        rxsetup.rx_data = buffer_rx;
        rxsetup.rx_length = 1;
        rxsetup.retransmissions_max = 3;

        I2C_MasterTransferData(I2CDEV, &rxsetup, I2C_TRANSFER_POLLING);
        *cfg = (int8_t)buffer_rx[0];
    return SUCCESS;
}
[/FONT]


When debugging, the vars are as follow:

[FONT=Courier New]i2cAddr    'H'   
cfg    0x10007f8f   
    *cfg    0   
buffer_tx    0x00000000   
    *buffer_tx    0   
buffer_rx    0x000000c8   
    *buffer_rx    'A'   
rxsetup    {...}   
    sl_addr7bit    0   
    tx_data    0x2007c000   
    tx_length    268468056   
    tx_count    32663   
    rx_data    0x00000001   
    rx_length    32644   
    rx_count    1073758208   
    retransmissions_max    0   
    retransmissions_count    1073758208   
    status    268468088   
    callback    0x00002da9 [/FONT]  

And I'm sent in the handler when running [FONT=Courier New]rxsetup.sl_addr7bit = i2cAddr;

[FONT=Arial]What have I missed this time ? I'm surprised by [/FONT][/FONT][FONT=Courier New]buffer_tx    0x00000000 [/FONT][FONT=Courier New]

Thanks.

[/FONT]
0 Kudos
Reply

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vthinsel on Thu Mar 03 09:45:14 MST 2011
I see ! I didn't understand it required a 7 bit....
Thanks for clarifying this. So depending if I make a read or write the trailing bit will be set accordingly I guess.
I'll check this as soon as I get home !
0 Kudos
Reply

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by igorsk on Thu Mar 03 09:26:12 MST 2011
The name "sl_addr7bit" implies it wants the 7-bit address (without the R/W bit).
0 Kudos
Reply

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vthinsel on Thu Mar 03 07:21:34 MST 2011
Hello,

144 is decimal.
It is 0x90, which matches the default DS1631 address

bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
1 0 0 1 A2 A1 A0 R/W

I'll double-check once I'm home.
Thanks

Vincent
0 Kudos
Reply

1,090 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by igorsk on Thu Mar 03 06:40:27 MST 2011
144 looks like an 8-bit address, not 7-bit. Try 72 (0x48).
0 Kudos
Reply