I2C Slave operation

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I have an I2C slave and an I2C master instantiated on a CY8C42 processor.  I have the SDA/SCL pins tied together with a 2200 ohm pullups to 3.3v.  externally.

   

The pins that are being used are P3.0-P4.0 and P3.1-P4.1.  I have set up the slave for an address of 0x58 and using the same address in a send start command, I can visually see the address go out but the slave does not acknowledge the transmission.

   

Code snippets are as follows:

   

Slave initialization:

   

  // initialize the TX/RX buffer
  I2CSlave_I2CSlaveInitReadBuf( anTxBuffer, MAX_XMT_BUFFER_SIZE );
  I2CSlave_I2CSlaveInitWriteBuf( anRxBuffer, MAX_RCV_BUFFER_SIZE );

   

  // initialize the SBC_I2C
  I2CSlave_Start( );
  
  // set the interrupt handler
  I2CSlave_SetCustomInterruptHandler( LocalIrqHandler );
  
  // force an address ( added just in case )
  I2CSlave_I2CSlaveSetAddress( 0x58 );

   

  // enable the interrupts
  I2CSlave_SetSlaveInterruptMode( I2CSlave_INTR_SLAVE_I2C_ARB_LOST |
                                  I2CSlave_INTR_SLAVE_I2C_NACK |
                                  I2CSlave_INTR_SLAVE_I2C_ACK |
                                  I2CSlave_INTR_SLAVE_I2C_WRITE_STOP |
                                  I2CSlave_INTR_SLAVE_I2C_STOP |
                                  I2CSlave_INTR_SLAVE_I2C_START |
                                  I2CSlave_INTR_SLAVE_I2C_ADDR_MATCH |
                                  I2CSlave_INTR_SLAVE_I2C_BUS_ERROR );

   

  // enable the intrrupt
  I2CSlave_EnableInt( );

   

 

   

Master initialization and transmission:

   

// start the I2C
  I2CMaster_Start( );
  
  // for debug only
  uStatus = I2CMaster_I2CMasterClearStatus( );
  uStatus = I2CMaster_I2CMasterSendStart( 0x58, I2CMaster_I2C_WRITE_XFER_MODE );
  if ( uStatus == I2CMaster_I2C_MSTR_NO_ERROR )
  {
    // now send a byte
    uStatus = I2CMaster_I2CMasterWriteByte( 0x1E );
    if ( uStatus == I2CMaster_I2C_MSTR_NO_ERROR )
    {
    }
  }

   

The first usuable status on send start returns a 0x0002.

   

Any ideas would be appreicated.

0 Likes
1 Solution
pacr_284376
Level 5
Level 5
100 replies posted 10 solutions authored 50 sign-ins

Have a good look at you oscilloscope diagram. Before starting i2c communication, SDA and SCL must be high. START condition just means SDA goes low while SCL stays high. I dont see that in your diagram. 

   

https://nl.wikipedia.org/wiki/I%C2%B2C-bus

View solution in original post

0 Likes
16 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum!

   

Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

Additional question: What board do you use? Self made?? Cypress Kit?? Which one???

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I am using the Cypress CY8CKIT-001 with a CY8CKIT-038 PSOC 4200 module plugin.

   

I have attached the file.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You do not sent an I2CMaster_I2CMasterSendStop(), so your

   

  else if ( uIrqSource & I2CSlave_INTR_SLAVE_I2C_WRITE_STOP )

   


is never executed.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

If I understand I2C, there should have been an ACK received on the start command.  This returned an error of 0x0002 which means the address byte was not nacked.  sending the stop afterward is redundant.  I have scope pictures which indicate that the bus was idle, a start was issued the address byte was sent out but was not acked by the slave.

0 Likes
Anonymous
Not applicable

   

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Check the p3_1 connection, the slave is not pulling low the line. Check the pin with a separate program if it can pull the resistor low.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

As a generic GPIO pin, it can pull the 2200 resistor to ground.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Yes, of course, but what I wanted to say is: Has P3_1 a defect and is no longer able to work as required or toes the pin act normally in the same environment? Make a new project, set the pin to "Open Drain, drives low", toggle the pin with a PWM and see if the levels are correct. Use the same board as before with your resistors applied.

   

 

   

Bob

0 Likes
pacr_284376
Level 5
Level 5
100 replies posted 10 solutions authored 50 sign-ins

Have a good look at you oscilloscope diagram. Before starting i2c communication, SDA and SCL must be high. START condition just means SDA goes low while SCL stays high. I dont see that in your diagram. 

   

https://nl.wikipedia.org/wiki/I%C2%B2C-bus

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Paddy, what do you think may be the reason for the missing start (except bad trigger)

   

 

   

Bob

0 Likes
Anonymous
Not applicable

The start is not missing, just the way it was triggered.  

   

0 Likes
Anonymous
Not applicable

I have verified the operation of the Master instantiated in the design with another slave device.  I have also tested the instantiated slave with an external master.  The problem remains that the slave does not acknowledge it's address.  The pin is capable of being pulled low when set as general purpose pin.

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I only have got a CY8CKIT-044 PSoC4-M Pioneer Kit.

   

Attached project works, external connections P4_0 <-> P3_0 and P4_1 <-> P3_1

   

                                                                               J3 10        J4 1         J3 9          J4 2

   

 

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks, I got it to work, I found a bent pin on the header that takes the plug in board.

   

I have another question,  according to the documentation, I can write a custom interrupt handler and process the interrupts that I am interested in and the normal interrupt handler is then processes it as well such as buffer commands.  I am only interested in knowing when a full buffer has been received.  If I use the poll method, I get the message into the buffer and everything works okay.

   

 

   

However, if I use the interrupt method, I get the interrupt on complete, however, there is no data in the buffer.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I am not able to deduct what exactly you are doing and what not works as expected. Can you please post a complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

Wouldn't be too bad also, when you start a new thread in a PSoC4 forum with a new heading. More forum members will look at it.

   

 

   

Bob

0 Likes
pacr_284376
Level 5
Level 5
100 replies posted 10 solutions authored 50 sign-ins

>> Paddy, what do you think may be the reason for the missing start (except bad trigger)

   

I dont know, I dont have a crystal ball. It could be as you suggested, could also be a hardware problem around the microprocessor which is overlooked.

   

 

   

Edit : (Sorry I didnt see the thread was allready continued on page 2)

0 Likes