2013-10-18

Coocox SPI debugging notes

// ***********************************************************************
// Program  - Fong EKG v5.0
// Function - Olimex EKG Board Evaluation
// Author   - TL Fong
// Build    - 2013.10.18.01
// Date     - 2013oct18hkt2138
// Hardware - Olimex/CooCox/MagicBlue/WHUT/Somy LPC1114/C14/301/FN28
//            Olimex EKG board (SHIELD-EKG/EMG Rev B, Bulgaria 2011)
// Software - GCC ARM 4.7, CoIDE 1.7.4,  CoLinkEx 1.1, Flash Magic v7.51
// ***********************************************************************

#include "test050.h" // main tests

// ***********************************************************************
// Main Function
// ***********************************************************************

int main()
{
...

testSpi01();

}

// ***********************************************************************
// End
// ***********************************************************************



// ***********************************************************************
// test050.h 2013oct18hkt2139
// ***********************************************************************

#include "led050.h"
#include "key050.h"
#include "spi050.h"

void testSpi01() // 2013oct18
{
// *** Blink LED at P09 ***
setupGpioPinOutputLow050(PortPinArrayP09); // setup GPIO pin as output
blinkLed0501(PortPinArrayP09); // blink led

// *** Test SPI loopback ***
loopBackSpi01();
}

...

// ***********************************************************************
// End
// ***********************************************************************



// ***********************************************************************
// spi050.h 2013oct18hkt2140
// ***********************************************************************

#include "lpc11xx_ssp.h"
#include "led050.h"

void loopBackSpi01()
{
// Setup and initialize buffers ***

#define BUFFER_SIZE 0x40
uint8_t Tx_Buf[BUFFER_SIZE];
uint8_t Rx_Buf[BUFFER_SIZE];

    xferBuffer_Init(Tx_Buf, Rx_Buf);

// Configure SPI peripheral ***

// SSP Configuration structure variable
SSP_CFG_Type SSP_ConfigStruct;

// Enable SSP0 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP0, ENABLE);

// Assign GPIO pins for SPI *** System hangs !!! ***
// SSP_SSP0PinsInit(SCK0_PIO2_11, ENABLE);

// Initialize SSP peripheral with default configuration
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP0, &SSP_ConfigStruct);

    // Enable SSP peripheral
    SSP_Cmd(LPC_SSP0, ENABLE);

    // Setup xfer data configuration struct

    SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = Tx_Buf;
    xferConfig.rx_data = Rx_Buf;
    xferConfig.length = BUFFER_SIZE;

    // Read and write SPI data *** System hangs !!! ***
    // SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);

    // Check if SPI transfer OK

    int xferStatus;

    xferStatus = xferStatusCheck(Tx_Buf, Rx_Buf);

    if (xferStatus == 1)
    blinkOneLed050(PortPinArrayP09, ONE_FIFTH_SECOND, ONE_HALF_SECOND, BLINK_2_TIMES);
    else
    blinkOneLed050(PortPinArrayP09, ONE_FIFTH_SECOND, ONE_HALF_SECOND, BLINK_4_TIMES);

}

// *** Private SPI test functions ***

void xferBuffer_Init(uint8_t Tx_Buf[BUFFER_SIZE], uint8_t Rx_Buf[BUFFER_SIZE] )
{
  uint8_t i;

    for (i = 0; i < BUFFER_SIZE; i++)
    {
    Tx_Buf[i] = i;
        Rx_Buf[i] = 0;
    }
}

 int xferStatusCheck(uint8_t Tx_Buf[BUFFER_SIZE], uint8_t Rx_Buf[BUFFER_SIZE])
{
  uint8_t i;
    uint8_t *src_addr = (int *) &Tx_Buf[0];
    uint8_t *dest_addr = (int *) &Rx_Buf[0];

    for ( i = 0; i < BUFFER_SIZE; i++ )
    {
    if ( *src_addr++ != *dest_addr++ )
        {
    return 0;
         }
    }
    return 1;
}

// ***********************************************************************
// End
// ***********************************************************************



No comments:

Post a Comment