Author Topic: PIA I2C Control  (Read 15516 times)

Offline hervé

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
PIA I2C Control
« on: November 02, 2009, 02:52:33 PM »
Hello,

I wanted to use PCF8574P, so I had the code to write the correct structure :

Code: [Select]
#define IO_EXPENDER_1_ADDR   0x40
static byte ucTrameIOEX1[] = {IO_EXPENDER_1_ADDR, 0xFF };   
fnWrite(IICPortID, (unsigned char *)ucTrameIOEX1, sizeof(ucTrameIOEX1))


The first write is correct but it look like the write buffer did not get empty : ptQUEQue->chars is incremented but never decremented.

I made following changes :
Code: [Select]
    case MASTER_REPEATED_START_SENT:                                     // (0x10) repeated start has been sent
    case MASTER_START_SENT:                                              // (0x08) start bit sent, now send address
        {
            unsigned long ulAddress = *ptIICQue->IIC_queue.get++;        // the address
//ADD//HP//021109//
if (ptIICQue->IIC_queue.chars)
ptIICQue->IIC_queue.chars--;
//

Code: [Select]
    case MASTER_TX_ADDRESS_NOT_ACKED:                                    // (0x20) the slave address has been sent but no ack was received
    case MASTER_TX_DATA_NOT_ACKED:                                       // (0x30) a byte of data has been sent but was not acked
    case MASTER_TX_DATA_ACKED:                                           // (0x28) a byte of data has been sent and acked
    case MASTER_TX_ADDRESS_ACKED:                                        // (0x18) the slave address was sent and we have received an ack - continue with the TX data
        if (ptIICQue->ucPresentLen != 0) {
            iic->I2CDAT = *ptIICQue->IIC_queue.get++;                    // send first data byte
//ADD//HP//021109//
if (ptIICQue->IIC_queue.chars)
ptIICQue->IIC_queue.chars--;
//


then it works....

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3243
    • View Profile
    • uTasker
Re: PIA I2C Control
« Reply #1 on: November 04, 2009, 12:37:08 AM »
Hi Hervé

Yes it seems there is an error here.

I tested the correction but found that the position of your first addition is not correct - it should be only in the write case (you are also decrementing in the read case, which will probably cause errors):

            if (ulAddress & 0x00000001) {                                // reading
                ...
            }
            else {
                ptIICQue->IIC_queue.chars--;
            }



Thanks!

Regards

Mark