2013-10-24

Max7219 test preparation notes

// ***********************************************************************
// Program  - Fong EKG v5.0
// Function - Olimex EKG Board Evaluation
// Author   - TL Fong
// Build    - 2013.10.24.01
// Date     - 2013oct24hkt1022
// 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 Function
// ***********************************************************************

int main()
{
// *** Completed tests ***
// testOlimexLedKey01();
// testWhutLedKey01();
// testOlimex7segmentLed01();
// testSpi03();
// testWhut7segmentLed01(); // OK 2013oct23
// testWhutLedP108(); // OK 2013oct23
// testOlimex7segmentLed0101();
// testOlimex7segmentLed0201();
// testBlinkP03()
// testMcp320801();
// testSspLoopBack04(); // not fully tested 2013oct24

testMcp3208();

    // testMax7219();

    return 0;
}

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


// ***********************************************************************
// test050.h 2013oct24hkt1022
// ***********************************************************************

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

void testMax7219()
{
// *** Blink LED at P03 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led

max7219v01();
}

void testMcp3208() // 2013oct24
{
// *** Blink LED at P03 ***
setupGpioPinOutputLow050(PortPinArrayP03); // setup GPIO pin as output
blinkLed0501(PortPinArrayP03); // blink led

// *** Test MCP3028 ***
mcp3208v02();
}

...

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

// ***********************************************************************
// spi050.h 2013oct24hkt0900
// ***********************************************************************

#include "gpio050.h"
#include "led050.h"
#include "lpc11xx_ssp.h"
#include "semihosting.h"
#include "stdio.h"

// ***********************************************************************
// Max7219 Functions
// ***********************************************************************

void max7219v01() // 2013oct24hkt1020
{
    // *** Print project title ***********************************************
printf("*** MAX7219 Test - 2013oct24hk0937 ***\n\n");


// *** Setup MAX7219 digit control register buffer ***********************
// Digit control register buffer
#define BUFFER_SIZE 2
#define ADDRESS_INDEX 0
#define DATA_INDEX 1

uint8_t digitControlRegisterBuffer[BUFFER_SIZE];
uint8_t dummyReceiveBuffer[BUFFER_SIZE];


// *** Set up SPI ********************************************************
// Setup SCLK and SSEL
setUpSpi050(SCK0_PIO0_6);
setupSpiSsel();

// Setup xferConfig
    SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = (void*)digitControlRegisterBuffer;
    xferConfig.rx_data = (void*)dummyReceiveBuffer;
    xferConfig.length = BUFFER_SIZE;


// *** Setup Max7219 digit and control ***********************************
    // Register addresses
#define NO_OP_ADDR 0x00
#define DIGIT_0_ADDR 0x01
    #define DIGIT_1_ADDR 0x02
#define DIGIT_2_ADDR 0x03
#define DIGIT_3_ADDR 0x04
#define DIGIT_4_ADDR 0x05
#define DIGIT_5_ADDR 0x06
#define DIGIT_6_ADDR 0x07
#define DIGIT_7_ADDR 0x08
#define DECODE_MODE_ADDR 0x09
#define INTENSITY       0x0a
#define SCAN_LIMIT_ADDR 0x0b
#define SHUTDOWN_ADDR   0x0c
#define DISPLAY_TEST     0x0f

// Control byte
#define SHUTDOWN_MODE 0x00
#define NORMAL_OPERATION_MODE 0x01


    // *** Test Max7219 ******************************************************
    uint8_t i;
    for (i = 0; i < 10000000; i++)
    {
    delayMilliSecond(1);
    setSselLow();
        SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
        setSselHigh();
    }
}

void max7219ShutDown(uint8_t digitControlRegisterBuffer[BUFFER_SIZE])
{
digitControlRegisterBuffer[ADDRESS_INDEX] = SHUTDOWN_ADDR;
digitControlRegisterBuffer[DATA_INDEX] = SHUTDOWN_MODE;
}

// ***********************************************************************
// End of max7219
// ***********************************************************************


// ***********************************************************************
// Mcp3208 Functions
// ***********************************************************************

void mcp3208v02() // 2013oct24hkt1034
{
    // *** Print title ***
printf("*** MCP3208 Test - 2013oct23hk1453 ***\n\n");

// Setup SPI0 with clock pin = P06
setUpSpi050(SCK0_PIO0_6);

// Setup SSEL0 pin = P02
setupSpiSsel();

    // Setup transfer buffers TxBuf, RxBuf
#define BUFFER_SIZE 3
uint8_t TxBuf[BUFFER_SIZE];
uint8_t RxBuf[BUFFER_SIZE];

    // Setup xferConfig = TxBuf, RxBuf
    SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = (void*)TxBuf;
    xferConfig.rx_data = (void*)RxBuf;
    xferConfig.length = BUFFER_SIZE;

    // Initialize MCP3208 Tx and Rx buffers

    // *** Select input mode and channel number ***

    uint8_t inputMode;
    uint8_t channelNumber;

    #define SINGLE_END_MODE 0x06; // bit 1 = 1
    #define DIFFERENTIAL_END_MODE 0x04; // bit 1 = 0

    inputMode = SINGLE_END_MODE;
channelNumber = 2;

    // *** Initialize TxBuf and RxBuf ***

    TxBuf[0] = inputMode | (channelNumber >> 2);
    TxBuf[1] = channelNumber << 0x6;
    TxBuf[2] = 0x00; // Don't care

RxBuf[0] = 0x00;
RxBuf[1] = 0x00;
RxBuf[2] = 0x00;

// *** Print TxBuf and RxBuf

char TxTitle[10];
char RxTitle[10];

strcpy(TxTitle, "TxBuf ");
strcpy(RxTitle, "RxBuf ");

// *** Before ADC ***
printf("\n*** Before ADC values of TxBuf and RxBuf *** \n\n");
printf("Index    0  1   2\n\n");
printXferBuffers(TxBuf, RxBuf, TxTitle, RxTitle);

// *** ADC once and print results ***

setSselLow();
    SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
    setSselHigh();

// *** After ADC (Ch 2 = 1.64V) ***
printf("\n*** After ADC (Ch 2 = 1.64V, ARef = 2.49V) *** \n\n");

printf("Index    0  1   2\n\n");
printXferBuffers(TxBuf, RxBuf, TxTitle, RxTitle);

// *** Print End of Test ***
printf("\n*** End of Test. *** \n\n");


    // *** calculate ADC results ***

    uint16_t adcOutputHex;

    // adcOutputHex = ((Rx_Buf[1] & 0x0f) * (2 ** 8)) + Rx_Buf[2];
    adcOutputHex = ((RxBuf[1] & 0x0f) * 256) + RxBuf[2];

    // *** Loop to display waveform by scope ***
    uint8_t i;
    for (i = 0; i < 10000000; i++)
    {
    delayMilliSecond(1);
    setSselLow();
        SSP_ReadWrite(LPC_SSP0, &xferConfig, SSP_TRANSFER_POLLING);
        setSselHigh();
    }
}

void printXferBuffers(uint8_t TxBuf[BUFFER_SIZE], uint8_t RxBuf[BUFFER_SIZE], char TxTitle[10], char RxTitle[10])
{
uint8_t Tx0 = TxBuf[0];
uint8_t Tx1 = TxBuf[1];
uint8_t Tx2 = TxBuf[2];

uint8_t Rx0 = RxBuf[0];
uint8_t Rx1 = RxBuf[1];
uint8_t Rx2 = RxBuf[2];

printf("%s %02x %02x %02x \n", TxTitle, Tx0, Tx1, Tx2);
printf("%s %02x %02x %02x \n", RxTitle, Rx0, Rx1, Rx2);
}

void setUpSpi050(SCK0_Position_Typedef sck0)
{
// Enable SSP0 block clock
SYSCON_AHBPeriphClockCmd(SYSCON_AHBPeriph_SSP0, ENABLE);

// Reset SSP0 and clock divider
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, ENABLE);
SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_SSP0, DISABLE);
SYSCON_SetSPI0ClockDiv(10);

// Assign GPIO pins for SPI
// SSP_SSP0PinsInit(sck0, ENABLE);
SSP_SSP0PinsInit(sck0, DISABLE); // Disable SSEL

// Initialize SSP with default configuration (Master mode, 8 bit data)
SSP_CFG_Type SSP_ConfigStruct;
SSP_ConfigStructInit(&SSP_ConfigStruct);
SSP_Init(LPC_SSP0, &SSP_ConfigStruct);

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

void setupSpiSsel()
{
setupGpioPinOutputLow050(PortPinArraySsel); // setup GPIO pin as output
}

void setSselLow()
{
setGpioDataPinLow01(PortPinArraySsel); // SSEL low
}

void setSselHigh()
{
setGpioDataPinHigh01(PortPinArraySsel); // SSEL low
}

/*

*** Sample output ***

*** MCP3208 Test - 2013oct23hk1453 ***

*** Before ADC values of TxBuf and RxBuf ***
Index    0  1   2
TxBuf  06 80 00
RxBuf  00 00 00

*** After ADC (Ch 2 = 1.64V, ARef = 2.49V) ***
Index    0  1   2
TxBuf  06 80 00
RxBuf  ff ea 7f

*** End of Test. ***

*/


// ***********************************************************************
// End of Mcp3208
// ***********************************************************************



.EN



No comments:

Post a Comment