SAM V70 I2C Issue

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All, 

 

I'm having trouble with I2C communication from a SAM V70 to a Cypress CY8CMBR3116 capacitive touch IC.

 

Using the twihs_master_read() and twihs_master_write() functions the IC configures absolutely fine. However once I begin reading from the touch chip in my main loop, the master_read function begins returning TWIHS_ERROR_TIMEOUT consistently, so my data never gets read.

 

Here is my read function:

bool Host_LowLevelRead(uint8_t slaveAddress, uint8_t readAddr, uint8_t *readBuffer, uint8_t numberOfBytes)
{
    twihs_packet_t packet_rx;
    packet_rx.chip = slaveAddress;
    packet_rx.addr[0] = readAddr; //First part of the address
    packet_rx.addr[1] = 0;//second part of the address
    packet_rx.addr[2] = 0;//second part of the address
    packet_rx.addr_length = CY8CMBR3xxx_REG_ADDRESS_LENGTH; //assign the length of the address
    packet_rx.buffer = (uint8_t *)readBuffer; //assign the buffer that will be transmitted
    packet_rx.length = numberOfBytes; //set the length of the buffer
    
    bool status = FALSE;                                       /* Default return is FALSE if anything goes wrong */
    uint32_t localBufStatus = 0;             /* Error status variable */
    uint8_t retryCount = CY8CMBR3xxx_RETRY_TIMES;                /* Retry count, in case of any issue */
        
    //twihs_send_clear(TWIHS0);

    do
    {
	
        /* Issue a non-blocking read */
        localBufStatus = twihs_master_read(TWIHS0, &packet_rx);
        
    } while((localBufStatus != TWIHS_SUCCESS) && ((--retryCount) != 0)); /* Repeat from beginning until all bytes are read successfully */
    
	if(localBufStatus != TWIHS_SUCCESS && !retryCount)
	{
		printf("[Host_LowLevelRead] localBufStatus: %d - retryCount = %d\r\n", localBufStatus, retryCount);
	}

    /* Check whether the transaction was successful or it timed-out */
    status = (retryCount) ? TRUE: FALSE;
    
    /* Return the status */
    return status;
}

 

I have also attached a screenshot of one of the transactions when analysed. I notice that though I am trying to read two bytes of data from 0xAA on the touch IC, the SAM V70 does not ACK the first 0x00 received from the touch IC. Any clue as to why the SAM would not acknowledge a received byte?

 

If I step through twihs_master_read function using the debugger over SWD, with a breakpoint on the RHR read, and repeatedly continuing to this point, my touch reads DO seem to function;

uint32_t twihs_master_read(Twihs *p_twihs, twihs_packet_t *p_packet)
{
	uint32_t status, cnt = p_packet->length;
	uint8_t *buffer = p_packet->buffer;
	uint32_t timeout = TWIHS_TIMEOUT;

	/* Check argument */
	if (cnt == 0) {
		return TWIHS_INVALID_ARGUMENT;
	}

	/* Set read mode, slave address and 3 internal address byte lengths */
	p_twihs->TWIHS_MMR = 0;
	p_twihs->TWIHS_MMR = TWIHS_MMR_MREAD | TWIHS_MMR_DADR(p_packet->chip) |
			((p_packet->addr_length << TWIHS_MMR_IADRSZ_Pos) &
			TWIHS_MMR_IADRSZ_Msk);

	/* Set internal address for remote chip */
	p_twihs->TWIHS_IADR = 0;
	p_twihs->TWIHS_IADR = twihs_mk_addr(p_packet->addr, p_packet->addr_length);

	/* Send a START Condition */
	p_twihs->TWIHS_CR = TWIHS_CR_START;

	while (cnt > 0) {
		status = p_twihs->TWIHS_SR;
		if (status & TWIHS_SR_NACK) {
			return TWIHS_RECEIVE_NACK;

		}
		if (!timeout--) {
			return TWIHS_ERROR_TIMEOUT;
		}
		/* Last byte ? */
		if (cnt == 1) {
			p_twihs->TWIHS_CR = TWIHS_CR_STOP;
		}

		if (!(status & TWIHS_SR_RXRDY)) {
			continue;
		}

		// BREAKING HERE
		*buffer++ = p_twihs->TWIHS_RHR;

		cnt--;
		timeout = TWIHS_TIMEOUT;
	}

	while (!(p_twihs->TWIHS_SR & TWIHS_SR_TXCOMP)) {
	}

	p_twihs->TWIHS_SR;

	return TWIHS_SUCCESS;
}

 

Any help or suggestions would be greatly appreciated.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cSmout wrote:
I have also attached a screenshot of one of the transactions when analysed. I notice that though I am trying to read two bytes of data from 0xAA on the touch IC, the SAM V70 does not ACK the first 0x00 received from the touch IC. Any clue as to why the SAM would not acknowledge a received byte?

If not already done I recommend to check the SCK/SDA signal hi/low levels with a scope. I've had systems with wrong pullup resistors.

SAME newbie

Last Edited: Wed. Mar 14, 2018 - 09:50 AM