|
|
|
@ -4,85 +4,126 @@
|
|
|
|
|
#include "usart.h"
|
|
|
|
|
#include "ascii.h"
|
|
|
|
|
#include "timer.h"
|
|
|
|
|
#include "spi.h"
|
|
|
|
|
#include "max7219.h"
|
|
|
|
|
|
|
|
|
|
unsigned char A[] = {0b00000000,0b00111100,0b01100110,0b01100110,0b01111110,0b01100110,0b01100110,0b01100110};
|
|
|
|
|
unsigned char B[] = {0b01111000,0b01001000,0b01001000,0b01110000,0b01001000,0b01000100,0b01000100,0b01111100};
|
|
|
|
|
unsigned char C[] = {0b00000000,0b00011110,0b00100000,0b01000000,0b01000000,0b01000000,0b00100000,0b00011110};
|
|
|
|
|
unsigned char D[] = {0b00000000,0b00111000,0b00100100,0b00100010,0b00100010,0b00100100,0b00111000,0b00000000};
|
|
|
|
|
unsigned char E[] = {0b00000000,0b00111100,0b00100000,0b00111000,0b00100000,0b00100000,0b00111100,0b00000000};
|
|
|
|
|
unsigned char F[] = {0b00000000,0b00111100,0b00100000,0b00111000,0b00100000,0b00100000,0b00100000,0b00000000};
|
|
|
|
|
unsigned char G[] = {0b00000000,0b00111110,0b00100000,0b00100000,0b00101110,0b00100010,0b00111110,0b00000000};
|
|
|
|
|
unsigned char H[] = {0b00000000,0b00100100,0b00100100,0b00111100,0b00100100,0b00100100,0b00100100,0b00000000};
|
|
|
|
|
unsigned char I[] = {0b00000000,0b00111000,0b00010000,0b00010000,0b00010000,0b00010000,0b00111000,0b00000000};
|
|
|
|
|
unsigned char J[] = {0b00000000,0b00011100,0b00001000,0b00001000,0b00001000,0b00101000,0b00111000,0b00000000};
|
|
|
|
|
unsigned char K[] = {0b00000000,0b00100100,0b00101000,0b00110000,0b00101000,0b00100100,0b00100100,0b00000000};
|
|
|
|
|
unsigned char L[] = {0b00000000,0b00100000,0b00100000,0b00100000,0b00100000,0b00100000,0b00111100,0b00000000};
|
|
|
|
|
unsigned char M[] = {0b00000000,0b00000000,0b01000100,0b10101010,0b10010010,0b10000010,0b10000010,0b00000000};
|
|
|
|
|
unsigned char N[] = {0b00000000,0b00100010,0b00110010,0b00101010,0b00100110,0b00100010,0b00000000,0b00000000};
|
|
|
|
|
unsigned char O[] = {0b00000000,0b00111100,0b01000010,0b01000010,0b01000010,0b01000010,0b00111100,0b00000000};
|
|
|
|
|
unsigned char P[] = {0b00000000,0b00111000,0b00100100,0b00100100,0b00111000,0b00100000,0b00100000,0b00000000};
|
|
|
|
|
unsigned char Q[] = {0b00000000,0b00111100,0b01000010,0b01000010,0b01000010,0b01000110,0b00111110,0b00000001};
|
|
|
|
|
unsigned char R[] = {0b00000000,0b00111000,0b00100100,0b00100100,0b00111000,0b00100100,0b00100100,0b00000000};
|
|
|
|
|
unsigned char S[] = {0b00000000,0b00111100,0b00100000,0b00111100,0b00000100,0b00000100,0b00111100,0b00000000};
|
|
|
|
|
unsigned char T[] = {0b00000000,0b01111100,0b00010000,0b00010000,0b00010000,0b00010000,0b00010000,0b00000000};
|
|
|
|
|
unsigned char U[] = {0b00000000,0b01000010,0b01000010,0b01000010,0b01000010,0b00100100,0b00011000,0b00000000};
|
|
|
|
|
unsigned char V[] = {0b00000000,0b00100010,0b00100010,0b00100010,0b00010100,0b00010100,0b00001000,0b00000000};
|
|
|
|
|
unsigned char W[] = {0b00000000,0b10000010,0b10010010,0b01010100,0b01010100,0b00101000,0b00000000,0b00000000};
|
|
|
|
|
unsigned char X[] = {0b00000000,0b01000010,0b00100100,0b00011000,0b00011000,0b00100100,0b01000010,0b00000000};
|
|
|
|
|
unsigned char Y[] = {0b00000000,0b01000100,0b00101000,0b00010000,0b00010000,0b00010000,0b00010000,0b00000000};
|
|
|
|
|
unsigned char Z[] = {0b00000000,0b00111100,0b00000100,0b00001000,0b00010000,0b00100000,0b00111100,0b00000000};
|
|
|
|
|
#include "i2c.h"
|
|
|
|
|
|
|
|
|
|
void timer_test(timerNo_t timer, pinNo_t pin)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
timerInitCounter(timer, 4000, 999, downCounting);
|
|
|
|
|
timerSart(timer);
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 10 ; i++)
|
|
|
|
|
{
|
|
|
|
|
while(!timerGetUpdateInterrupt(timer));
|
|
|
|
|
timerClearUpdateInterrupt(timer);
|
|
|
|
|
pinToggle(pin);
|
|
|
|
|
}
|
|
|
|
|
pinWrite(pin,0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void timer_capture_compare_test(timerNo_t timer)
|
|
|
|
|
{
|
|
|
|
|
uint16_t i = 0;
|
|
|
|
|
timerInitCounter(timer, 100, 99, downCounting);
|
|
|
|
|
// We use pin PA3 (Arduino header A2)
|
|
|
|
|
//timerInitOutputCompare(timer, toggle, 4, pinA3, 2,0, 300);
|
|
|
|
|
timerInitOutputCompare(timer, pwm_normal, 2, pinB3, 2,0, 900);
|
|
|
|
|
timerSart(timer);
|
|
|
|
|
|
|
|
|
|
while(1){
|
|
|
|
|
delayMs(200);
|
|
|
|
|
timerSetCounterCompareValue(timer, 2, i);
|
|
|
|
|
i += 10;
|
|
|
|
|
if(i>99) i = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void printBinary32(uint32_t toPrint, uint8_t lsbFirst)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char pt;
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
if(lsbFirst)
|
|
|
|
|
{
|
|
|
|
|
print_Usart(usart2, "Bit Pos | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|");
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
print_Usart(usart2, "Bits |");
|
|
|
|
|
for(i=0; i < 32; i++)
|
|
|
|
|
{
|
|
|
|
|
pt = (toPrint >> i) & 1;
|
|
|
|
|
usartSendChar(usart2, ' ');
|
|
|
|
|
usartSendChar(usart2, pt + 0x30);
|
|
|
|
|
usartSendChar(usart2, '|');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
print_Usart(usart2, "Bit Pos |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|");
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
print_Usart(usart2, "Bits |");
|
|
|
|
|
for(i=0; i < 32; i++)
|
|
|
|
|
{
|
|
|
|
|
pt = (toPrint >> (31-i)) & 1;
|
|
|
|
|
usartSendChar(usart2, ' ');
|
|
|
|
|
usartSendChar(usart2, pt + 0x30);
|
|
|
|
|
usartSendChar(usart2, '|');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void printBinary8(uint8_t toPrint, uint8_t lsbFirst)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char pt;
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
if(lsbFirst)
|
|
|
|
|
{
|
|
|
|
|
print_Usart(usart2, "Bit Pos | 0| 1| 2| 3| 4| 5| 6| 7|");
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
print_Usart(usart2, "Bits |");
|
|
|
|
|
for(i=0; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
pt = (toPrint >> i) & 1;
|
|
|
|
|
usartSendChar(usart2, ' ');
|
|
|
|
|
usartSendChar(usart2, pt + 0x30);
|
|
|
|
|
usartSendChar(usart2, '|');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
print_Usart(usart2, "Bit Pos | 7| 6| 5| 4| 3| 2| 1| 0|");
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
print_Usart(usart2, "Bits |");
|
|
|
|
|
for(i=0; i < 8; i++)
|
|
|
|
|
{
|
|
|
|
|
pt = (toPrint >> (7-i)) & 1;
|
|
|
|
|
usartSendChar(usart2, ' ');
|
|
|
|
|
usartSendChar(usart2, pt + 0x30);
|
|
|
|
|
usartSendChar(usart2, '|');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
uint8_t i = 0;
|
|
|
|
|
uint8_t j = 0;
|
|
|
|
|
|
|
|
|
|
uint8_t f[] = {
|
|
|
|
|
0x00,
|
|
|
|
|
0x7E,
|
|
|
|
|
0x40,
|
|
|
|
|
0x40,
|
|
|
|
|
0x3E,
|
|
|
|
|
0x40,
|
|
|
|
|
0x40,
|
|
|
|
|
0x40
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint8_t matrix[] = {
|
|
|
|
|
0xAA,
|
|
|
|
|
0xFF,
|
|
|
|
|
0xAA,
|
|
|
|
|
0xFF,
|
|
|
|
|
0xAA,
|
|
|
|
|
0xFF,
|
|
|
|
|
0xAA,
|
|
|
|
|
0xFF};
|
|
|
|
|
|
|
|
|
|
uint8_t matrix_1[] = {
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11,
|
|
|
|
|
0x11};
|
|
|
|
|
spi_ch_t spi_test_channel;
|
|
|
|
|
max7219_t ledMatrix;
|
|
|
|
|
|
|
|
|
|
// making array with all available timers
|
|
|
|
|
uint16_t slaveAddress = 0xC0;
|
|
|
|
|
uint8_t registerToRead = 0x00;
|
|
|
|
|
uint8_t i2cRecieved = 0;
|
|
|
|
|
uint8_t i2cToWrite = 0xFF;
|
|
|
|
|
uint8_t i2cDataLenght = 1;
|
|
|
|
|
i2c_t i2c_1;
|
|
|
|
|
|
|
|
|
|
delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library
|
|
|
|
|
|
|
|
|
|
pinConfig(pinB3, output, pushPull, output, def_speed);
|
|
|
|
|
pinConfig(pinB3, output, pushPull, def_res, def_speed);
|
|
|
|
|
pinConfig(pinA0, input, def_stage, pullDown, def_speed);
|
|
|
|
|
|
|
|
|
|
setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
usartInit( usart2,
|
|
|
|
|
pinA2,
|
|
|
|
|
pinA15,
|
|
|
|
@ -93,10 +134,11 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
|
//clears screen and send the wellcome messgae
|
|
|
|
|
print_Usart(usart2, ASCII_clear);
|
|
|
|
|
print_Usart(usart2, "HEllooo to our KED project\n\r");
|
|
|
|
|
print_Usart(usart2, "Hello to our KED project\n\r");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(i = 0 ; i < 5 ; i++) {
|
|
|
|
|
//blinks 10 times to indicate the sicsessfull init if the device
|
|
|
|
|
for(i = 0 ; i < 2 ; i++) {
|
|
|
|
|
delayMs(100);
|
|
|
|
|
pinToggle(pinB3);
|
|
|
|
|
delayMs(100);
|
|
|
|
@ -104,141 +146,41 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
|
|
|
|
pinWrite(pinB3,0);
|
|
|
|
|
|
|
|
|
|
pinInit(pinA3);
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
|
|
|
|
|
//pinConfig(pinA6, alternate, floating, pullDown, veryFast);
|
|
|
|
|
pinConfig(pinA3, output, pushPull, output, veryFast);
|
|
|
|
|
|
|
|
|
|
// spi hardware channel setup
|
|
|
|
|
spiInitMaster(SPI_CH_1,
|
|
|
|
|
SPI_NONINVERTED,
|
|
|
|
|
SPI_CAPTURE_ON_FIRST_CLK_TRANSITION,
|
|
|
|
|
SPI_MSB_FIRST,
|
|
|
|
|
SPI_DOUPLEX,
|
|
|
|
|
7,
|
|
|
|
|
pinA5,
|
|
|
|
|
0,
|
|
|
|
|
pinA7,
|
|
|
|
|
0,
|
|
|
|
|
pinA6,
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
|
|
spiSetupCH(&spi_test_channel, SPI_CH_1, pinA3);
|
|
|
|
|
|
|
|
|
|
// LED Matrix object setup
|
|
|
|
|
//ledMatrix.spiCH = &spi_test_channel;
|
|
|
|
|
max7219_init(&ledMatrix, &spi_test_channel);
|
|
|
|
|
|
|
|
|
|
spiEnable(SPI_CH_1);
|
|
|
|
|
i2cInit(&i2c_1, I2C_CH_1, i2cModeMaster, 0x00,0x00, i2cAddressCountSingle, i2cAddressSizeSevenBits, i2cSpeedStandart, i2cOpperationPolling, i2cClockStretchingDisable, i2cWakeUpDisabled);
|
|
|
|
|
/*
|
|
|
|
|
* MAX7219 hoockup for this example
|
|
|
|
|
*
|
|
|
|
|
* Signal pin nucleo
|
|
|
|
|
* --------------------------
|
|
|
|
|
* MOSI pinA7 A6
|
|
|
|
|
* MISO pinA6 A5
|
|
|
|
|
* CLK pinA5 A4
|
|
|
|
|
* CS pinA4 A3
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(i = 0 ; i < 10 ; i++) {
|
|
|
|
|
delayMs(50);
|
|
|
|
|
pinToggle(pinB3);
|
|
|
|
|
delayMs(50);
|
|
|
|
|
}
|
|
|
|
|
i2cRead(&i2c_1, &slaveAddress, ®isterToRead, &i2cRecieved, &i2cDataLenght);
|
|
|
|
|
printBinary8(i2cRecieved,0);
|
|
|
|
|
|
|
|
|
|
max7219_testDisplay(&ledMatrix,1);
|
|
|
|
|
delayMs(500);
|
|
|
|
|
max7219_testDisplay(&ledMatrix,0);
|
|
|
|
|
max7219_shutdownDiaply(&ledMatrix,0);
|
|
|
|
|
max7219_setDecodeMode(&ledMatrix, NO_DECODE_DIGIT_7_TO_0);
|
|
|
|
|
max7219_setScanLimit(&ledMatrix, DSIPLAX_DIGIT_7_TO_0);
|
|
|
|
|
max7219_setIntensity(&ledMatrix,0x01);
|
|
|
|
|
|
|
|
|
|
max7219_ledMatrixSetLED(&ledMatrix,0,0);
|
|
|
|
|
delayMs(1000);
|
|
|
|
|
max7219_setAllLEDsOff(&ledMatrix);
|
|
|
|
|
/*
|
|
|
|
|
for(i=0; i < 8; i++) {
|
|
|
|
|
max7219_ledMatrixSetLED(&ledMatrix,i,i);
|
|
|
|
|
delayMs(100);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, F);
|
|
|
|
|
//max7219_ledMatrixSetLED(&ledMatrix, 0, 0);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, A);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, T);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, I);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_setAllLEDsOff(&ledMatrix);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, G);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, E);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, N);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, T);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, I);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_setAllLEDsOff(&ledMatrix);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, E);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, D);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, W);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, I);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_printLedMatrix(&ledMatrix, N);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
max7219_setAllLEDsOff(&ledMatrix);
|
|
|
|
|
delayMs(300);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
|
for(i=0; i < 0x8; i++) {
|
|
|
|
|
max7219_ledMatrixSetLED(&ledMatrix,i,i+j);
|
|
|
|
|
delayMs(100);
|
|
|
|
|
}
|
|
|
|
|
//delayMs(10);
|
|
|
|
|
j++;
|
|
|
|
|
if(j > 7) j =0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
while(1){
|
|
|
|
|
pinToggle(pinB3);
|
|
|
|
|
dispTest(&ledMatrix);
|
|
|
|
|
//max7219_test_display(&spi_test_channel);
|
|
|
|
|
}
|
|
|
|
|
registerToRead += 1;
|
|
|
|
|
|
|
|
|
|
i2cRead(&i2c_1, &slaveAddress, ®isterToRead, &i2cRecieved, &i2cDataLengh);
|
|
|
|
|
printBinary8(i2cRecieved,0);
|
|
|
|
|
*/
|
|
|
|
|
for(i = 0 ; i < 100 ; i++) {
|
|
|
|
|
pinWrite(pinB3, 1);
|
|
|
|
|
//pinWrite(pinA4,1);
|
|
|
|
|
delayMs(100);
|
|
|
|
|
pinWrite(pinB3, 0);
|
|
|
|
|
//pinWrite(pinA4,0);
|
|
|
|
|
delayMs(900);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
registerToRead = 1;
|
|
|
|
|
i2cToWrite = 0xFF;
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
//i2cWrite(&i2c_1, &slaveAddress, ®isterToRead, &i2cToWrite, &i2cDataLenght);
|
|
|
|
|
|
|
|
|
|
//timer_capture_compare_test(timer_2);
|
|
|
|
|
//print_Usart(usart2, "All is working fine \r\n");
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
i2cRead(&i2c_1, &slaveAddress, ®isterToRead, &i2cRecieved,&i2cDataLenght);
|
|
|
|
|
|
|
|
|
|
printBinary8(i2cRecieved,0);
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
print_Usart(usart2, "\n\r");
|
|
|
|
|
print_Usart(usart2, "All is working fine\n\r");
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
delayMs(100);
|
|
|
|
|
pinToggle(pinB3);
|
|
|
|
|
delayMs(100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|