2013-11-19

SPI troubleshooting notes


SPI troubleshooting notes

*** test Max7219 - 2013nov19 ***

slaveSelectPortPinArray Port = 00 
slaveSelectPortPinArray Pin  = 02 

*** End of test ***

*** test Max7219 - 2013nov19 ***

slaveSelectPortPinArray Port = 00 
slaveSelectPortPinArray Pin  = 07 

*** End of test ***

*** test Max7219 - 2013nov19 ***

slaveSelectPortPinArray Port = 00 
slaveSelectPortPinArray Pin  = 11 

*** End of test ***

*** test Max7219 - 2013nov19 ***

slaveSelectPortPinArray Port = 02 
slaveSelectPortPinArray Pin  = 05 

*** End of test ***

*** test Max7219 - 2013nov19 ***

slaveSelectPortPinArray Port = 01 
slaveSelectPortPinArray Pin  = 09 

*** End of test ***

*** test Max7219 - 2013nov19 ***

slaveSelectPortPinArray Port = 02 
slaveSelectPortPinArray Pin  = 04 

*** End of test



// ***************************************************************************
// Program  - Fong EKG v5.08
// Function - Testing Olimex EKG
// Author   - TL Fong
// Build    - 2013.11.19.01
// Date     - 2013nov19hkt1255
// Hardware - WuyinS/Olimex/CooCox/MagicBlue/WHUT/Somy LPC1114/C14/301
//            Olimex EKG/EMG R.B 2011
// Software - CoIDE 1.7.5, CoLinkEx 1.1, Flash Magic v7.66, GCC ARM 4.7
// **************************************************************************

#include "test050.h"

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

int main()
{
// *** Test Olimex LPC1114 #2 2013nov19 hkt2100 **********************************
// testMax7219DigitV0701(SPI_CHANNEL_1); // good, but need power up reset
// testMax7219DigitV0701(SPI_CHANNEL_0); // good, but need power up reset

testMax7219v0702(SPI_CHANNEL_0, SLAVE_SELECT_0);
testMax7219v0702(SPI_CHANNEL_0, SLAVE_SELECT_1);
testMax7219v0702(SPI_CHANNEL_0, SLAVE_SELECT_2);
testMax7219v0702(SPI_CHANNEL_0, SLAVE_SELECT_3);
testMax7219v0702(SPI_CHANNEL_0, SLAVE_SELECT_4);
testMax7219v0702(SPI_CHANNEL_0, SLAVE_SELECT_5);
}

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




// ***********************************************************************
// test050.h 2013nov19hkt2101
// ***********************************************************************

#include "led050.h"
#include "key050.h"
#include "spi050.h"
#include "adc050.h"
#include "eeprom050.h"
#include "mled050.h"


// ***************************************************************************
// Function - Test MAX7219
// Date     - 2013nov19
// ***************************************************************************

void testMax7219v0702(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
printf("\n\n*** test Max7219 - 2013nov19 ***\n\n");
// spiSetup060(spiChannelNumber, slaveSelectNumber);
spiSetup070(spiChannelNumber, slaveSelectNumber); // this version will NOT
                                                 // repeatedly set up SPI
displayMcp7219Display8DigitsV0701(spiChannelNumber, slaveSelectNumber, \
                         2, 2, 3, 4, 5, 6, 7, 8);
printf("\n*** End of test ***\n");
}

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



// ***********************************************************************
// mled050.h 2013nov10hkt1152
// MAX7219 4-digit 7-segment and 8x8 matrix LED
// ***********************************************************************

#include "spi050.h"

// *** MAX7219 Register Address Map ***
#define NO_OP_ADDR 0x00
#define DIGIT_ADDR_0 0x01
#define DIGIT_ADDR_1 0x02
#define DIGIT_ADDR_2 0x03
#define DIGIT_ADDR_3 0x04
#define DIGIT_ADDR_4 0x05
#define DIGIT_ADDR_5 0x06
#define DIGIT_ADDR_6 0x07
#define DIGIT_ADDR_7 0x08
#define DECODE_MODE_ADDR 0x09
#define INTENSITY_ADDR     0x0a
#define SCAN_LIMIT_ADDR 0x0b
#define OPERATION_ADDR   0x0c // Shutdown address actually
#define DISPLAY_TEST_ADDR   0x0f

// *** MAX7219 Command Format ***
#define SHUT_DOWN              0x00
#define NORMAL                 0x01
#define CODE_B_ALL_DIGITS      0xff
#define NO_DECODE_ALL_DIGITS   0x00
#define DECODE_ALL_8_DIGITS    0xff
#define NO_DECODE_ALL_8_DIGITS 0x00
#define NO_DECODE_ALL_8_ROWS   0x00
#define DISPLAY_8_DIGITS       0x07
#define SCAN_ALL_8_DIGITS      0x07
#define SCAN_ALL_8_ROWS        0x07

// *** Data Constants ***
#define DEVICE_1 1
#define DEVICE_2 2
#define DEVICE_3 3
#define DEVICE_4 4

#define LED_DRIVER_1 1
#define LED_DRIVER_2 2
#define LED_DRIVER_3 3
#define LED_DRIVER_4 4

#define DIGIT_0 0
#define DIGIT_1 1
#define DIGIT_2 2
#define DIGIT_3 3
#define DIGIT_4 4
#define DIGIT_5 5
#define DIGIT_6 6
#define DIGIT_7 7
#define DIGIT_8 8
#define DIGIT_9 9
#define CHAR_HYPHEN 10
#define CHAR_E 11
#define CHAR_H 12
#define CHAR_L 13
#define CHAR_P 14
#define CHAR_BLANK 15

#define PATTERN_ALL_ON 0xff
#define PATTERN_ALL_OFF 0x00

#define ADDRESS_INDEX 0
#define DATA_INDEX 1

#define MAX_DEVICE_NUMBER 16
#define MAX_BUFFER_SIZE 32
#define MAX_MATRIX_NUMBER 4

uint8_t char_A[5] = {0x7E, 0x11, 0x11, 0x11, 0x7E};
uint8_t char_K[5] = {0x41, 0x22, 0x14, 0x08, 0x7f};
uint8_t char_O[5] = {0x3E, 0x41, 0x41, 0x41, 0x3E};

uint8_t CharBigO[8] = {0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00, 0x00};
uint8_t CharBigK[8] = {0x41, 0x22, 0x14, 0x08, 0x7F, 0x00, 0x00, 0x00};

uint8_t TriGram0[8] = {0x54, 0x54, 0x54, 0x00, 0x54, 0x54, 0x54, 0x00};


void displayMcp7219Display8DigitsV0701(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                                uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4, \
                                uint8_t digit5, uint8_t digit6, uint8_t digit7, uint8_t digit8)
{
setupMcp7219DigitModeV0701(spiChannelNumber, slaveSelectNumber);
    display8LedDigit060(spiChannelNumber, slaveSelectNumber, LED_DRIVER_1, digit1, digit2, \
               digit3, digit4, digit5, digit6, digit7, digit8);
}

void display8LedDigit060(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t ledDriverNumber, \
           uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4, \
           uint8_t digit5, uint8_t digit6, uint8_t digit7, uint8_t digit8)
{
shutDownLedDriver060(spiChannelNumber, slaveSelectNumber, ledDriverNumber);
displayLedDigit060(spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_7, digit1);
    displayLedDigit060(spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_6, digit2);
    displayLedDigit060(spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_5, digit3);
    displayLedDigit060(spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_4, digit4);
    displayLedDigit060(spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_3, digit5);
    displayLedDigit060(spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_2, digit6);
    displayLedDigit060(spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_1, digit7);
    displayLedDigit060(spiChannelNumber, slaveSelectNumber, ledDriverNumber, DIGIT_ADDR_0, digit8);
    startUpLedDriver060(spiChannelNumber, slaveSelectNumber, ledDriverNumber);
}

void displayLedDigit060(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
               uint8_t deviceNumber, uint8_t digitAddress, uint8_t digitData)
{
writeLedDriverCommand060(spiChannelNumber, slaveSelectNumber, deviceNumber, digitAddress, digitData);
}

void setupMcp7219DigitModeV0701(uint8_t spiChannelNumber, uint8_t slaveSelectNumber)
{
writeMcp7219Command0701(spiChannelNumber, slaveSelectNumber, DECODE_MODE_ADDR, DECODE_ALL_8_DIGITS);
writeMcp7219Command0701(spiChannelNumber, slaveSelectNumber, SCAN_LIMIT_ADDR, SCAN_ALL_8_DIGITS);
writeMcp7219Command0701(spiChannelNumber, slaveSelectNumber, OPERATION_ADDR, SHUT_DOWN);
}

void setupDecodeMode060(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t driverNumber, uint8_t decodeMode)
{
writeLedDriverCommand060(spiChannelNumber, slaveSelectNumber, driverNumber, DECODE_MODE_ADDR, decodeMode);
}

void setupScanLimit060(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t driverNumber, uint8_t scanLimit)
{
writeLedDriverCommand060(spiChannelNumber, slaveSelectNumber, driverNumber, SCAN_LIMIT_ADDR, scanLimit);
}

void shutDownLedDriver060(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t driverNumber)
{
writeLedDriverCommand060(spiChannelNumber, slaveSelectNumber, driverNumber, OPERATION_ADDR, SHUT_DOWN);
}

void startUpLedDriver060(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, uint8_t driverNumber)
{
writeLedDriverCommand060(spiChannelNumber, slaveSelectNumber, driverNumber, OPERATION_ADDR, NORMAL);
}

void writeLedDriverCommand060(uint8_t spiChannelNumber, uint8_t slaveSelectNumber, \
                     uint8_t deviceNumber, uint8_t commandRegisterAddress, uint8_t command)
{
uint8_t txBuffer[MAX_BUFFER_SIZE];
uint8_t rxBuffer[MAX_BUFFER_SIZE];

SSP_DATA_SETUP_Type xferConfig;
    xferConfig.tx_data = txBuffer;
    xferConfig.rx_data = rxBuffer;
    xferConfig.length =  deviceNumber * 2;

    txBuffer[ADDRESS_INDEX] = commandRegisterAddress;
txBuffer[DATA_INDEX] = command;

    int i;
    for (i = 1; i < deviceNumber; i++)
    {
        txBuffer[(i * 2) + ADDRESS_INDEX] = NO_OP_ADDR;
}

    spiTransmit060(spiChannelNumber, slaveSelectNumber, xferConfig);
}



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



.END

No comments:

Post a Comment