AnsweredAssumed Answered

Problems using SPI component SynchroMaster

Question asked by Andrew Clegg on Nov 11, 2014
Latest reply on Nov 17, 2014 by Andrew Clegg

I am using the SynchroMaster processorexpert component to talk to a simple 4-wire SPI component attached to a TWR-K60F120m via the primary elevator. My settings are included at the bottom. I am using simple code to test (below): check buffers are empty, send the characters, wait for the transmit buffer to empty and the receive buffer to fill up, read out all the characters.

 

My problem seems to be that I always get back 0xff bytes no matter what should be coming back. I know that the SPI slave device works correctly as it has been tested on a different microcontroller. I am going to try to get my hands on a logic analyzer, but for now does anyone have any idea what might be causing this?

 

Thanks

 

int spi_readwrite(unsigned char *sendBuf, unsigned char *recvBuf, int size) {   if (size <= 0) {        return -1;   }   int retval;   unsigned char discard;    ana_Enable();    if (ana_GetCharsInTxBuf() != 0) {        printf("spi_readwrite called with non-empty transmit buffer\n");        return -11;   }    if (ana_GetCharsInRxBuf() != 0) {        printf("spi_readwrite called with non-empty receive buffer\n");        return -12;   }    // Send first   for (int i=0; i<size; i++) {        // Send character        retval = ana_SendChar(sendBuf[i]);        switch (retval) {        case ERR_OK:             break; // move on to the next character        case ERR_SPEED:             printf("sendChar(%d): ERR_SPEED\n", i);             return -2;        case ERR_DISABLED:             printf("sendChar(%d): ERR_DISABLED\n", i);             return -3;        case ERR_TXFULL:             printf("sendChar(%d): ERR_TXFULL\n", i);             return -4;        default:             printf("sendChar(%d): Unknown response code %d\n", i, retval);             return -5;        }   }    // Wait for transmit buffer to empty   int tx_bufsize;   while (1) {       tx_bufsize = ana_GetCharsInTxBuf();       if (tx_bufsize == 0) {            break;       }   }    // Wait for receive buffer to fill up   int rx_bufsize;   while (1) {        rx_bufsize = ana_GetCharsInRxBuf();        if (rx_bufsize == size) {             break;        }   }    // Receive   for (int i=0; i<size; i++) {        if (recvBuf == NULL) {             retval = ana_RecvChar(&discard);        } else {             retval = ana_RecvChar(&recvBuf[i]);        }        switch (retval) {             case ERR_OK:                  break;             case ERR_SPEED:                  printf("recvChar(%d): ERR_SPEED\n", i);                  return -6;             case ERR_RXEMPTY:                  printf("recvChar(%d): ERR_RX_EMPTY\n", i);                  return -7;             case ERR_OVERRUN:                  printf("recvChar(%d): ERR_OVERRUN\n", i);                  return -8;             case ERR_FAULT:                  printf("recvChar(%d): ERR_FAULT\n", i);                  return -9;             default:                  printf("recvChar(%d): Unknown response code %d\n", i, retval);                  return -10;        }   }  ana_Disable();   return 0; } 

 

spi_settings.png

Outcomes