Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
9a322b36f9 | |||
1cdfc0dd46 | |||
1eb92e4ac2 | |||
1466d7d7b7 | |||
f5d468ca75 | |||
|
572ac11d4e | ||
|
67cfe20124 | ||
09a8a38509 | |||
403899797e | |||
|
3888af0897 | ||
|
13caa9be2d | ||
68b68612bc | |||
db9acf73c7 | |||
b35fba020b | |||
0ed69f882b | |||
dd1b47ccef | |||
173b14e9c6 | |||
5365ee21d4 | |||
1a95acae24 | |||
|
a26ce94b70 | ||
581539ae81 | |||
c1a88864f6 | |||
85a9222ec2 | |||
4e6849a9c5 | |||
de0027b97d | |||
4addb8c974 | |||
c9cc2e7876 | |||
7cb77f2a68 | |||
a954f4749e | |||
5c445ac79f | |||
d3e4d2229e | |||
b9b5e40dd3 | |||
4c5aad63e2 | |||
f5e85192fd | |||
e3157ff9cb | |||
2a886045f6 | |||
31def3b096 | |||
4d08cdd37f | |||
af86d55583 | |||
3ca2af459e | |||
3c737ffaa8 | |||
9cd2d3d614 | |||
7476dcd4c4 | |||
3c43db92f6 | |||
04bfd6622c | |||
46e64840df | |||
b26149cfe2 | |||
5a59d32dc3 | |||
57a0245774 | |||
ae60699c7c | |||
bc8b59a1d5 | |||
b6db95ab78 |
@ -1,73 +0,0 @@
|
|||||||
#include "SPIMaster.h"
|
|
||||||
|
|
||||||
|
|
||||||
void Print(char *data2, int lenght){
|
|
||||||
for(int i = 0; i < lenght; i++) {
|
|
||||||
Serial.print(data2[i], HEX);
|
|
||||||
Serial.print(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(9600);
|
|
||||||
SPI_MasterInit();
|
|
||||||
Serial.println("Master Initialization ");
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
// All clear
|
|
||||||
// 0x00 - черный, остальное белое
|
|
||||||
// char data[] = {0x01, 0x00, 0};
|
|
||||||
|
|
||||||
// Setpage 1
|
|
||||||
// 0x00 - 0x07
|
|
||||||
// char data[] = {0x02, 0x01, 0};
|
|
||||||
|
|
||||||
// Add symbol
|
|
||||||
// char data[] = {0x03, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0F, 0};
|
|
||||||
|
|
||||||
// Delete symbol
|
|
||||||
// Кол-во символов
|
|
||||||
// char data[] = {0x04, 0x04, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0};
|
|
||||||
|
|
||||||
// Draw Pixel
|
|
||||||
// x, y, color
|
|
||||||
// char data[] = {0x05, 0x15, 0x15, 0x01, 0};
|
|
||||||
|
|
||||||
// Draw Line
|
|
||||||
// x1, y1, x2, y2, color
|
|
||||||
// char data[] = {0x06, 0x15, 0x15, 0x45, 0x45, 0x01, 0};
|
|
||||||
|
|
||||||
// Draw Circle
|
|
||||||
// x, y, r, color, fill
|
|
||||||
// char data[] = {0x07, 0x15, 0x15, 0x15, 0x01, 0x00, 0};
|
|
||||||
|
|
||||||
// Draw Rectangle
|
|
||||||
// x, y, width, height, color, fill
|
|
||||||
// char data[] = {0x08, 0x15, 0x15, 0x25, 0x25, 0x01, 0x00, 0};
|
|
||||||
|
|
||||||
// Draw Char
|
|
||||||
// x, y, charIndex, fill
|
|
||||||
// char data[] = {0x09, 0x15, 0x15, 0x05, 0x00, 0};
|
|
||||||
|
|
||||||
char data[] = {0x01, 0x00, 0};
|
|
||||||
int length = sizeof(data);
|
|
||||||
Serial.println();
|
|
||||||
Serial.print("Start: ");
|
|
||||||
Print(data, length);
|
|
||||||
Serial.println();
|
|
||||||
|
|
||||||
char checking = crc8(data, length-1);
|
|
||||||
int size = sizeof(data) / sizeof(data[0]);
|
|
||||||
data[size - 1] = checking;
|
|
||||||
Serial.println(checking, HEX);
|
|
||||||
|
|
||||||
Serial.print("End: ");
|
|
||||||
Print(data, length);
|
|
||||||
Serial.println();
|
|
||||||
|
|
||||||
SPI_MasterTransmit(data, length);
|
|
||||||
_delay_ms(5000);
|
|
||||||
}
|
|
@ -1,58 +0,0 @@
|
|||||||
|
|
||||||
#include "SPIMaster.h"
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include <util/delay.h>
|
|
||||||
|
|
||||||
void SPI_MasterInit(void)
|
|
||||||
{
|
|
||||||
DDR_SPI = (1 << DD_MOSI) | (1 << DD_SCK) | (1 << DD_SS);
|
|
||||||
DDRB |= (1<<DDB2);
|
|
||||||
SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1);
|
|
||||||
// SPCR = (1 << SPE) | (1 << MSTR) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPI_MasterTransmit(char *data, int length)
|
|
||||||
{
|
|
||||||
PORTB &= ~(1<<2);
|
|
||||||
|
|
||||||
for(int i = 0; i < length; i++) {
|
|
||||||
SPDR = data[i]; // отправляем байт массива
|
|
||||||
while (!(SPSR & (1 << SPIF))); // ждем, пока байт передастся
|
|
||||||
}
|
|
||||||
|
|
||||||
PORTB |= (1<<2);
|
|
||||||
}
|
|
||||||
|
|
||||||
char CRC8(char *data, int length) {
|
|
||||||
char crc = 0x00;
|
|
||||||
char poly = 0x07; // полином для CRC8
|
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
crc ^= data[i]; // XOR текущего байта с crc
|
|
||||||
|
|
||||||
for (int j = 0; j < length; j++) {
|
|
||||||
if (crc & 0x80) { // если старший бит crc равен 1
|
|
||||||
crc = (crc << 1) ^ poly; // сдвигаем crc на 1 бит влево и XOR с полиномом
|
|
||||||
} else {
|
|
||||||
crc <<= 1; // иначе просто сдвигаем на 1 бит влево
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
char crc8(char *data, int len) {
|
|
||||||
char crc = 0x00;
|
|
||||||
while (len--) {
|
|
||||||
crc ^= *data++;
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
if (crc & 0x80) {
|
|
||||||
crc = (crc << 1) ^ 0x07;
|
|
||||||
} else {
|
|
||||||
crc <<= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return crc;
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
#ifndef SPIMaster_h
|
|
||||||
#define SPIMaster_h
|
|
||||||
|
|
||||||
#define DDR_SPI DDRB
|
|
||||||
#define DD_MOSI PB3
|
|
||||||
#define DD_MISO PB4
|
|
||||||
#define DD_SCK PB5
|
|
||||||
#define DD_SS PB2
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SPI_MasterInit(void);
|
|
||||||
void SPI_MasterTransmit(char *data, int length);
|
|
||||||
char CRC8(char *data, int length);
|
|
||||||
char crc8(char *data, int len);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,87 +0,0 @@
|
|||||||
//master
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include <util/delay.h>
|
|
||||||
|
|
||||||
#define DDR_SPI DDRB
|
|
||||||
#define DD_MOSI PB3
|
|
||||||
#define DD_MISO PB4
|
|
||||||
#define DD_SCK PB5
|
|
||||||
#define DD_SS PB2
|
|
||||||
|
|
||||||
void SPI_MasterInit(void)
|
|
||||||
{
|
|
||||||
DDR_SPI = (1 << DD_MOSI) | (1 << DD_SCK) | (1 << DD_SS);
|
|
||||||
DDRB |= (1<<DDB2); // set SS as output
|
|
||||||
SPCR = (1 << SPE) | (1 << MSTR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Print(char *data2, int lenght){
|
|
||||||
Serial.println("----");
|
|
||||||
for(int i = 0; i < lenght; i++) {
|
|
||||||
Serial.print(data2[i], HEX);
|
|
||||||
Serial.print(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPI_MasterTransmit(char *data, int length)
|
|
||||||
{
|
|
||||||
PORTB &= ~(1<<2);
|
|
||||||
|
|
||||||
int size = sizeof(data) / sizeof(data[0]);
|
|
||||||
// Serial.println();
|
|
||||||
|
|
||||||
for(int i = 0; i < length; i++) {
|
|
||||||
SPDR = data[i]; // отправляем байт массива
|
|
||||||
// Serial.print(data[i], HEX);
|
|
||||||
// Serial.print(" ");
|
|
||||||
while (!(SPSR & (1 << SPIF))); // ждем, пока байт передастся
|
|
||||||
}
|
|
||||||
|
|
||||||
PORTB |= (1<<2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(2000000);
|
|
||||||
SPI_MasterInit();
|
|
||||||
Serial.println("Master Initialization ");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Функция для вычисления контрольной суммы XOR
|
|
||||||
char CRC8(char *data, int length) {
|
|
||||||
char crc = 0x00;
|
|
||||||
char poly = 0x07; // полином для CRC8
|
|
||||||
|
|
||||||
for (int i = 0; i < length-2; i++) {
|
|
||||||
crc ^= data[i]; // XOR текущего байта с crc
|
|
||||||
|
|
||||||
for (int j = 0; j < length; j++) {
|
|
||||||
if (crc & 0x80) { // если старший бит crc равен 1
|
|
||||||
crc = (crc << 1) ^ poly; // сдвигаем crc на 1 бит влево и XOR с полиномом
|
|
||||||
} else {
|
|
||||||
crc <<= 1; // иначе просто сдвигаем на 1 бит влево
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
char data[] = {6, 1, 2, 3, 4, 5, 7, 0};
|
|
||||||
|
|
||||||
int length = sizeof(data);
|
|
||||||
|
|
||||||
const int last = data [ (sizeof(data) / sizeof(data[0]))-1];
|
|
||||||
|
|
||||||
char checking = CRC8(data, length-1);
|
|
||||||
int size = sizeof(data) / sizeof(data[0]);
|
|
||||||
data[size - 1] = checking;
|
|
||||||
Print(data, size);
|
|
||||||
// Serial.println(last);
|
|
||||||
|
|
||||||
SPI_MasterTransmit(data, length);
|
|
||||||
_delay_ms(1000);
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
#include "aSPISlave.h"
|
|
||||||
#include "bCommands.h"
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
Serial.begin(2000000);
|
|
||||||
SPI_SlaveInit();
|
|
||||||
|
|
||||||
Serial.println();
|
|
||||||
Serial.println("Initialization ");
|
|
||||||
}
|
|
||||||
|
|
||||||
void processSPI(void (*callback)(char*)) {
|
|
||||||
if (PINB & (1 << 2)) {
|
|
||||||
if (index > 1) {
|
|
||||||
char checkSum = CRC8(data, index - 1);
|
|
||||||
char lastElement = data[index - 1];
|
|
||||||
if (lastElement == checkSum) {
|
|
||||||
callback(data);
|
|
||||||
index = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
processSPI(SetCommand);
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
#include "aSPISlave.h"
|
|
||||||
#include <avr/io.h>
|
|
||||||
|
|
||||||
ISR(SPI_STC_vect) {
|
|
||||||
char received = SPDR;
|
|
||||||
data[index] = received;
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPI_SlaveInit(void) {
|
|
||||||
DDR_SPI = (1 << DD_MISO);
|
|
||||||
SPCR = (1 << SPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
char CRC8(char *data, int length) {
|
|
||||||
char crc = 0x00;
|
|
||||||
char poly = 0x07; // полином для CRC8
|
|
||||||
|
|
||||||
for (int i = 0; i < length - 2; i++) {
|
|
||||||
crc ^= data[i]; // XOR текущего байта с crc
|
|
||||||
|
|
||||||
for (int j = 0; j < length; j++) {
|
|
||||||
if (crc & 0x80) { // если старший бит crc равен 1
|
|
||||||
crc = (crc << 1) ^ poly; // сдвигаем crc на 1 бит влево и XOR с полиномом
|
|
||||||
} else {
|
|
||||||
crc <<= 1; // иначе просто сдвигаем на 1 бит влево
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
#ifndef aSPISlave_h
|
|
||||||
#define aSPISlave_h
|
|
||||||
|
|
||||||
#define DDR_SPI DDRB
|
|
||||||
#define DD_MOSI PB3
|
|
||||||
#define DD_MISO PB4
|
|
||||||
#define DD_SCK PB5
|
|
||||||
#define DD_SS PB2
|
|
||||||
|
|
||||||
extern int index;
|
|
||||||
extern char data[];
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SPI_SlaveInit(void);
|
|
||||||
char CRC8(char *data, int length);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,17 +0,0 @@
|
|||||||
#include "bCommands.h"
|
|
||||||
|
|
||||||
void SetCommand(char *datalist, int lenght) {
|
|
||||||
char command = datalist[0];
|
|
||||||
char result[lenght];
|
|
||||||
char *ptr = &datalist[1];
|
|
||||||
strcpy(result, ptr);
|
|
||||||
switch (command) {
|
|
||||||
case 6:
|
|
||||||
AddSymbol(result,lenght);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddSymbol(char *symbols, int lenght) {
|
|
||||||
// Выполнение команды
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
#ifndef bCommands_h
|
|
||||||
#define bCommands_h
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SetCommand(char *datalist, int lenght);
|
|
||||||
void AddSymbol(char *symbols, int lenght);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,58 +0,0 @@
|
|||||||
#include <avr/io.h>
|
|
||||||
#include "SPISlave.h"
|
|
||||||
|
|
||||||
static int index = 0;
|
|
||||||
static int arIndex = 0;
|
|
||||||
static char data[255];
|
|
||||||
|
|
||||||
void SPI_SlaveInit(void)
|
|
||||||
{
|
|
||||||
DDR_SPI = (1 << DD_MISO);
|
|
||||||
SPCR = (1 << SPE) | (1 << SPIE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Функция для вычисления контрольной суммы XOR
|
|
||||||
char CRC8(char *data, int length) {
|
|
||||||
char crc = 0x00;
|
|
||||||
char poly = 0x07; // полином для CRC8
|
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
crc ^= data[i]; // XOR текущего байта с crc
|
|
||||||
|
|
||||||
for (int j = 0; j < length; j++) {
|
|
||||||
if (crc & 0x80) { // если старший бит crc равен 1
|
|
||||||
crc = (crc << 1) ^ poly; // сдвигаем crc на 1 бит влево и XOR с полиномом
|
|
||||||
} else {
|
|
||||||
crc <<= 1; // иначе просто сдвигаем на 1 бит влево
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
char crc8(char *data, int len) {
|
|
||||||
char crc = 0x00;
|
|
||||||
while (len--) {
|
|
||||||
crc ^= *data++;
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
if (crc & 0x80) {
|
|
||||||
crc = (crc << 1) ^ 0x07;
|
|
||||||
} else {
|
|
||||||
crc <<= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Проверка массива на ноль
|
|
||||||
char checkArray(char *arr, int size) {
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
if (arr[i] != 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
#ifndef SPISlave_H
|
|
||||||
#define SPISlave_H
|
|
||||||
|
|
||||||
#define DDR_SPI DDRB
|
|
||||||
#define DD_MOSI PB3
|
|
||||||
#define DD_MISO PB4
|
|
||||||
#define DD_SCK PB5
|
|
||||||
#define DD_SS PB2
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SPI_SlaveInit(void);
|
|
||||||
char CRC8(char *data, int length);
|
|
||||||
char checkArray(char *arr, int size);
|
|
||||||
|
|
||||||
char crc8(char *data, int len);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,424 +0,0 @@
|
|||||||
|
|
||||||
#include "SPISlave.h"
|
|
||||||
// #include <GyverOLED.h>
|
|
||||||
#include <GyverOLED.h>
|
|
||||||
GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> oled;
|
|
||||||
|
|
||||||
#define DDR_SPI DDRB
|
|
||||||
#define DD_MOSI PB3
|
|
||||||
#define DD_MISO PB4
|
|
||||||
#define DD_SCK PB5
|
|
||||||
#define DD_SS PB2
|
|
||||||
|
|
||||||
|
|
||||||
// GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> oled;
|
|
||||||
|
|
||||||
static int index = 0;
|
|
||||||
static int arIndex = 0;
|
|
||||||
static char data[64];
|
|
||||||
|
|
||||||
// void SPI_SlaveInit(void)
|
|
||||||
// {
|
|
||||||
// DDR_SPI = (1 << DD_MISO);
|
|
||||||
// SPCR = (1 << SPE) | (1 << SPIE);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// biblary
|
|
||||||
|
|
||||||
|
|
||||||
// внутренние константы
|
|
||||||
#define OLED_WIDTH 128
|
|
||||||
#define OLED_HEIGHT_64 0x12
|
|
||||||
#define OLED_64 0x3F
|
|
||||||
#define OLED_32 0x1F
|
|
||||||
|
|
||||||
#define OLED_DISPLAY_OFF 0xAE
|
|
||||||
#define OLED_DISPLAY_ON 0xAF
|
|
||||||
|
|
||||||
#define OLED_COMMAND_MODE 0x00
|
|
||||||
#define OLED_ONE_COMMAND_MODE 0x80
|
|
||||||
#define OLED_DATA_MODE 0x40
|
|
||||||
#define OLED_ONE_DATA_MODE 0xC0
|
|
||||||
|
|
||||||
#define OLED_ADDRESSING_MODE 0x20
|
|
||||||
#define OLED_HORIZONTAL 0x00
|
|
||||||
#define OLED_VERTICAL 0x01
|
|
||||||
|
|
||||||
#define OLED_NORMAL_V 0xC8
|
|
||||||
#define OLED_FLIP_V 0xC0
|
|
||||||
#define OLED_NORMAL_H 0xA1
|
|
||||||
#define OLED_FLIP_H 0xA0
|
|
||||||
|
|
||||||
#define OLED_CONTRAST 0x81
|
|
||||||
#define OLED_SETCOMPINS 0xDA
|
|
||||||
#define OLED_SETVCOMDETECT 0xDB
|
|
||||||
#define OLED_CLOCKDIV 0xD5
|
|
||||||
#define OLED_SETMULTIPLEX 0xA8
|
|
||||||
#define OLED_COLUMNADDR 0x21
|
|
||||||
#define OLED_PAGEADDR 0x22
|
|
||||||
#define OLED_CHARGEPUMP 0x8D
|
|
||||||
|
|
||||||
#define OLED_NORMALDISPLAY 0xA6
|
|
||||||
#define OLED_INVERTDISPLAY 0xA7
|
|
||||||
|
|
||||||
#define BUFSIZE_128x64 (128*64/8)
|
|
||||||
|
|
||||||
#define SCREEN_WIDTH 128
|
|
||||||
#define SCREEN_HEIGHT 64
|
|
||||||
|
|
||||||
#define OLED_ADDR 0x3C
|
|
||||||
|
|
||||||
const uint8_t _maxRow = 7;
|
|
||||||
const uint8_t _maxY = SCREEN_HEIGHT - 1;
|
|
||||||
const uint8_t _maxX = SCREEN_WIDTH - 1;
|
|
||||||
|
|
||||||
// ========== I2C ==========
|
|
||||||
#define I2C_FREQ 100000UL
|
|
||||||
|
|
||||||
void i2c_begin(uint8_t address)
|
|
||||||
{
|
|
||||||
TWBR = ((F_CPU / I2C_FREQ) - 16) / 2; // Расчет предделителя для заданной частоты
|
|
||||||
TWAR = (address << 1); // Установка адреса устройства
|
|
||||||
}
|
|
||||||
|
|
||||||
void i2c_endTransaction()
|
|
||||||
{
|
|
||||||
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO); // Отправка условия STOP
|
|
||||||
}
|
|
||||||
|
|
||||||
void i2c_beginTransmission(uint8_t address)
|
|
||||||
{
|
|
||||||
TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN); // Отправка условия START
|
|
||||||
while (!(TWCR & (1 << TWINT))); // Ожидание завершения START
|
|
||||||
|
|
||||||
TWDR = (address << 1); // Отправка адреса устройства
|
|
||||||
TWCR = (1 << TWINT) | (1 << TWEN); // Отправка адреса
|
|
||||||
while (!(TWCR & (1 << TWINT))); // Ожидание завершения передачи адреса
|
|
||||||
}
|
|
||||||
|
|
||||||
void i2c_write(uint8_t data)
|
|
||||||
{
|
|
||||||
TWDR = data; // Запись данных
|
|
||||||
TWCR = (1 << TWINT) | (1 << TWEN); // Отправка данных
|
|
||||||
while (!(TWCR & (1 << TWINT))); // Ожидание завершения передачи данных
|
|
||||||
}
|
|
||||||
|
|
||||||
// ========== Sender ==========
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t _writes = 0;
|
|
||||||
|
|
||||||
void sendData(uint8_t data) {
|
|
||||||
sendByteRaw(data);
|
|
||||||
_writes++;
|
|
||||||
if (_writes >= 16) {
|
|
||||||
endTransm();
|
|
||||||
beginData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendByteRaw(uint8_t data) {
|
|
||||||
i2c_write(data);
|
|
||||||
}
|
|
||||||
void sendCommand(uint8_t cmd1) {
|
|
||||||
beginOneCommand();
|
|
||||||
sendByteRaw(cmd1);
|
|
||||||
endTransm();
|
|
||||||
}
|
|
||||||
|
|
||||||
void sendCommand(uint8_t cmd1, uint8_t cmd2) {
|
|
||||||
beginCommand();
|
|
||||||
sendByteRaw(cmd1);
|
|
||||||
sendByteRaw(cmd2);
|
|
||||||
endTransm();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setWindow(int x0, int y0, int x1, int y1) {
|
|
||||||
beginCommand();
|
|
||||||
sendByteRaw(OLED_COLUMNADDR);
|
|
||||||
sendByteRaw(constrain(x0, 0, _maxX));
|
|
||||||
sendByteRaw(constrain(x1, 0, _maxX));
|
|
||||||
sendByteRaw(OLED_PAGEADDR);
|
|
||||||
sendByteRaw(constrain(y0, 0, _maxRow));
|
|
||||||
sendByteRaw(constrain(y1, 0, _maxRow));
|
|
||||||
endTransm();
|
|
||||||
}
|
|
||||||
|
|
||||||
void beginData() {
|
|
||||||
startTransm();
|
|
||||||
sendByteRaw(OLED_DATA_MODE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void beginCommand() {
|
|
||||||
startTransm();
|
|
||||||
sendByteRaw(OLED_COMMAND_MODE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void beginOneCommand() {
|
|
||||||
startTransm();
|
|
||||||
sendByteRaw(OLED_ONE_COMMAND_MODE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void endTransm() {
|
|
||||||
i2c_endTransaction();
|
|
||||||
_writes = 0;
|
|
||||||
}
|
|
||||||
void startTransm() {
|
|
||||||
i2c_beginTransmission(OLED_ADDR);
|
|
||||||
}
|
|
||||||
|
|
||||||
void oled_init(){
|
|
||||||
i2c_begin(OLED_ADDR);
|
|
||||||
beginCommand();
|
|
||||||
|
|
||||||
// 15
|
|
||||||
sendData(OLED_DISPLAY_OFF);
|
|
||||||
sendData(OLED_CLOCKDIV);
|
|
||||||
sendData(0x80);
|
|
||||||
sendData(OLED_CHARGEPUMP);
|
|
||||||
sendData(0x14);
|
|
||||||
sendData(OLED_ADDRESSING_MODE);
|
|
||||||
sendData(OLED_VERTICAL);
|
|
||||||
sendData(OLED_NORMAL_H);
|
|
||||||
sendData(OLED_NORMAL_V);
|
|
||||||
sendData(OLED_CONTRAST);
|
|
||||||
sendData(0x7F);
|
|
||||||
sendData(OLED_SETVCOMDETECT);
|
|
||||||
sendData(0x40);
|
|
||||||
sendData(OLED_NORMALDISPLAY);
|
|
||||||
sendData(OLED_DISPLAY_ON);
|
|
||||||
// 15
|
|
||||||
|
|
||||||
endTransm();
|
|
||||||
beginCommand();
|
|
||||||
sendData(OLED_SETCOMPINS);
|
|
||||||
sendData(OLED_HEIGHT_64);
|
|
||||||
sendData(OLED_SETMULTIPLEX);
|
|
||||||
sendData(OLED_64);
|
|
||||||
endTransm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ISR(SPI_STC_vect)
|
|
||||||
{
|
|
||||||
char received = SPDR;
|
|
||||||
data[index] = received;
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(9600);
|
|
||||||
SPI_SlaveInit();
|
|
||||||
|
|
||||||
oled_init();
|
|
||||||
oled.fill(0);
|
|
||||||
oled.setScale(3);
|
|
||||||
oled.home();
|
|
||||||
|
|
||||||
Serial.println();
|
|
||||||
Serial.println("Initialization ");
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetCommand(char *data2, int length){
|
|
||||||
char command = data2[0];
|
|
||||||
// Отрезать 1 элемент от оставшихся
|
|
||||||
|
|
||||||
Serial.print("\nReceived command: ");
|
|
||||||
Serial.println(command, HEX);
|
|
||||||
switch (command){
|
|
||||||
case 1:
|
|
||||||
AllClear(&data2[1], length-1);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
SetPage(&data2[1], length-1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// case 6:
|
|
||||||
// PrintMassive(&data2[1], length-1);
|
|
||||||
// break;
|
|
||||||
case 4:
|
|
||||||
AddSymbol(&data2[1], length-1);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
DelSymbol(&data2[1], length-1);
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
DrawPixel(&data2[1], length-1);
|
|
||||||
PrintMassive(&data2[1], length-1);
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
DrawLine(&data2[1], length-1);
|
|
||||||
break;
|
|
||||||
case 8:
|
|
||||||
DrawCircle(&data2[1], length-1);
|
|
||||||
break;
|
|
||||||
case 9:
|
|
||||||
DrawRectangle(&data2[1], length-1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PrintMassive(uint8_t *symbols, int lenght){
|
|
||||||
Serial.print("Received Add: ");
|
|
||||||
|
|
||||||
// oled.setScale(3); // масштаб текста (1..4)
|
|
||||||
// oled.home(); // курсор в 0,0
|
|
||||||
// oled.print("Привет!");
|
|
||||||
for(int i = 0; i < lenght - 1; i++) {
|
|
||||||
char str[3];
|
|
||||||
sprintf(str, "%01X", symbols[i]);
|
|
||||||
Serial.print(str);
|
|
||||||
Serial.print(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Another
|
|
||||||
// command 1
|
|
||||||
void AllClear(char *symbols, int lenght){
|
|
||||||
int param = symbols[0];
|
|
||||||
if (param == 1){
|
|
||||||
oled.fill(0);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
oled.fill(255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// command 2
|
|
||||||
void SetPage(char *symbols, int lenght){
|
|
||||||
int x = symbols[0];
|
|
||||||
int y = symbols[1];
|
|
||||||
oled.setCursor(x,y);
|
|
||||||
}
|
|
||||||
|
|
||||||
// command 4
|
|
||||||
void AddSymbol(char *symbols, int lenght) {
|
|
||||||
for (int i = 0; i < lenght - 1; i++) {
|
|
||||||
oled.print(symbols[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// command 5
|
|
||||||
void DelSymbol(char *symbols, int lenght) {
|
|
||||||
for (int i = 0; i < lenght - 1; i++) {
|
|
||||||
oled.print(symbols[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// command 6
|
|
||||||
void DrawPixel(char *symbols, int lenght){
|
|
||||||
int x = symbols[0];
|
|
||||||
int y = symbols[1];
|
|
||||||
int color = symbols[2];
|
|
||||||
oled.dot(x,y,color);
|
|
||||||
}
|
|
||||||
|
|
||||||
// command 7
|
|
||||||
void DrawLine(char *symbols, int lenght){
|
|
||||||
int x = symbols[0];
|
|
||||||
int y = symbols[1];
|
|
||||||
int x1 = symbols[2];
|
|
||||||
int y1 = symbols[3];
|
|
||||||
int color = symbols[4];
|
|
||||||
oled.line(x,y,x1,y1,color);
|
|
||||||
}
|
|
||||||
|
|
||||||
// command 8
|
|
||||||
void DrawCircle(char *symbols, int lenght){
|
|
||||||
int x = symbols[0];
|
|
||||||
int y = symbols[1];
|
|
||||||
int r = symbols[2];
|
|
||||||
int color = symbols[3];
|
|
||||||
oled.circle(x,y,r,color);
|
|
||||||
}
|
|
||||||
|
|
||||||
// command 9
|
|
||||||
void DrawRectangle(char *symbols, int lenght){
|
|
||||||
int x = symbols[0];
|
|
||||||
int y = symbols[1];
|
|
||||||
int x1 = symbols[2];
|
|
||||||
int y1 = symbols[3];
|
|
||||||
int color = symbols[4];
|
|
||||||
oled.rect(x,y,x1,y1,color);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Функция для вычисления контрольной суммы XOR
|
|
||||||
// char CRC8(char *data, int length) {
|
|
||||||
// char crc = 0x00;
|
|
||||||
// char poly = 0x07; // полином для CRC8
|
|
||||||
|
|
||||||
// for (int i = 0; i < length-2; i++) {
|
|
||||||
// crc ^= data[i]; // XOR текущего байта с crc
|
|
||||||
|
|
||||||
// for (int j = 0; j < length; j++) {
|
|
||||||
// if (crc & 0x80) { // если старший бит crc равен 1
|
|
||||||
// crc = (crc << 1) ^ poly; // сдвигаем crc на 1 бит влево и XOR с полиномом
|
|
||||||
// } else {
|
|
||||||
// crc <<= 1; // иначе просто сдвигаем на 1 бит влево
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return crc;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Вывод массива
|
|
||||||
void arrayOut(uint8_t *arr, int size){
|
|
||||||
Serial.print("Array: ");
|
|
||||||
for(int i = 0; i < size;i++){
|
|
||||||
char str[3];
|
|
||||||
sprintf(str, "%02X", arr[i]);
|
|
||||||
Serial.print(str);
|
|
||||||
Serial.print(" ");
|
|
||||||
}
|
|
||||||
Serial.println(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Проверка массива на ноль
|
|
||||||
// char checkArray(char *arr, int size) {
|
|
||||||
// for (int i = 0; i < size; i++) {
|
|
||||||
// if (arr[i] != 0) {
|
|
||||||
// return 1;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// TODO: где то длина массива неправильно летит
|
|
||||||
void loop() {
|
|
||||||
if(PINB & (1 << 2)){
|
|
||||||
if(index > 0){
|
|
||||||
|
|
||||||
arrayOut(data, index);
|
|
||||||
|
|
||||||
char sum = 0;
|
|
||||||
sum = crc8(data, index-1);
|
|
||||||
|
|
||||||
char checkNull = 0;
|
|
||||||
char last_1 = data[index - 1];
|
|
||||||
|
|
||||||
Serial.println(sum, HEX);
|
|
||||||
|
|
||||||
if (last_1 == sum){
|
|
||||||
Serial.println();
|
|
||||||
Serial.println("Старт вывода массивов");
|
|
||||||
Serial.println(sum, HEX);
|
|
||||||
|
|
||||||
SetCommand(data, index);
|
|
||||||
// oled.print(data[0]);
|
|
||||||
Serial.println("Стоп вывода массивов");
|
|
||||||
index = 0;
|
|
||||||
return;
|
|
||||||
}else{
|
|
||||||
Serial.println("Nothing ...");
|
|
||||||
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
@ -1,20 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
|
||||||
# Atmel Studio Solution File, Format Version 11.00
|
|
||||||
Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "SPI_", "SPI_\SPI_.cproj", "{37275DFD-0CE5-467A-9F25-7A9E49FF51C2}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|AVR = Debug|AVR
|
|
||||||
Release|AVR = Release|AVR
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{37275DFD-0CE5-467A-9F25-7A9E49FF51C2}.Debug|AVR.ActiveCfg = Debug|AVR
|
|
||||||
{37275DFD-0CE5-467A-9F25-7A9E49FF51C2}.Debug|AVR.Build.0 = Debug|AVR
|
|
||||||
{37275DFD-0CE5-467A-9F25-7A9E49FF51C2}.Release|AVR.ActiveCfg = Release|AVR
|
|
||||||
{37275DFD-0CE5-467A-9F25-7A9E49FF51C2}.Release|AVR.Build.0 = Release|AVR
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
BIN
SPI_/SPI_.atsuo
BIN
SPI_/SPI_.atsuo
Binary file not shown.
@ -1,136 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit!
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
SHELL := cmd.exe
|
|
||||||
RM := rm -rf
|
|
||||||
|
|
||||||
USER_OBJS :=
|
|
||||||
|
|
||||||
LIBS :=
|
|
||||||
PROJ :=
|
|
||||||
|
|
||||||
O_SRCS :=
|
|
||||||
C_SRCS :=
|
|
||||||
S_SRCS :=
|
|
||||||
S_UPPER_SRCS :=
|
|
||||||
OBJ_SRCS :=
|
|
||||||
ASM_SRCS :=
|
|
||||||
PREPROCESSING_SRCS :=
|
|
||||||
OBJS :=
|
|
||||||
OBJS_AS_ARGS :=
|
|
||||||
C_DEPS :=
|
|
||||||
C_DEPS_AS_ARGS :=
|
|
||||||
EXECUTABLES :=
|
|
||||||
OUTPUT_FILE_PATH :=
|
|
||||||
OUTPUT_FILE_PATH_AS_ARGS :=
|
|
||||||
AVR_APP_PATH :=$$$AVR_APP_PATH$$$
|
|
||||||
QUOTE := "
|
|
||||||
ADDITIONAL_DEPENDENCIES:=
|
|
||||||
OUTPUT_FILE_DEP:=
|
|
||||||
LIB_DEP:=
|
|
||||||
LINKER_SCRIPT_DEP:=
|
|
||||||
|
|
||||||
# Every subdirectory with source files must be described here
|
|
||||||
SUBDIRS :=
|
|
||||||
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
C_SRCS += \
|
|
||||||
../SPIMaster.c \
|
|
||||||
../SPI_.c
|
|
||||||
|
|
||||||
|
|
||||||
PREPROCESSING_SRCS +=
|
|
||||||
|
|
||||||
|
|
||||||
ASM_SRCS +=
|
|
||||||
|
|
||||||
|
|
||||||
OBJS += \
|
|
||||||
SPIMaster.o \
|
|
||||||
SPI_.o
|
|
||||||
|
|
||||||
OBJS_AS_ARGS += \
|
|
||||||
SPIMaster.o \
|
|
||||||
SPI_.o
|
|
||||||
|
|
||||||
C_DEPS += \
|
|
||||||
SPIMaster.d \
|
|
||||||
SPI_.d
|
|
||||||
|
|
||||||
C_DEPS_AS_ARGS += \
|
|
||||||
SPIMaster.d \
|
|
||||||
SPI_.d
|
|
||||||
|
|
||||||
OUTPUT_FILE_PATH +=SPI_.elf
|
|
||||||
|
|
||||||
OUTPUT_FILE_PATH_AS_ARGS +=SPI_.elf
|
|
||||||
|
|
||||||
ADDITIONAL_DEPENDENCIES:=
|
|
||||||
|
|
||||||
OUTPUT_FILE_DEP:= ./makedep.mk
|
|
||||||
|
|
||||||
LIB_DEP+=
|
|
||||||
|
|
||||||
LINKER_SCRIPT_DEP+=
|
|
||||||
|
|
||||||
|
|
||||||
# AVR32/GNU C Compiler
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
./%.o: .././%.c
|
|
||||||
@echo Building file: $<
|
|
||||||
@echo Invoking: AVR/GNU C Compiler : 4.8.1
|
|
||||||
$(QUOTE)E:\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -x c -funsigned-char -funsigned-bitfields -DDEBUG -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328p -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)" -o "$@" "$<"
|
|
||||||
@echo Finished building: $<
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# AVR32/GNU Preprocessing Assembler
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# AVR32/GNU Assembler
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ifneq ($(MAKECMDGOALS),clean)
|
|
||||||
ifneq ($(strip $(C_DEPS)),)
|
|
||||||
-include $(C_DEPS)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Add inputs and outputs from these tool invocations to the build variables
|
|
||||||
|
|
||||||
# All Target
|
|
||||||
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)
|
|
||||||
|
|
||||||
$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP)
|
|
||||||
@echo Building target: $@
|
|
||||||
@echo Invoking: AVR/GNU Linker : 4.8.1
|
|
||||||
$(QUOTE)E:\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="SPI_.map" -Wl,--start-group -Wl,-lm -Wl,--end-group -Wl,--gc-sections -mmcu=atmega328p
|
|
||||||
@echo Finished building target: $@
|
|
||||||
"E:\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "SPI_.elf" "SPI_.hex"
|
|
||||||
"E:\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "SPI_.elf" "SPI_.eep" || exit 0
|
|
||||||
"E:\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "SPI_.elf" > "SPI_.lss"
|
|
||||||
"E:\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "SPI_.elf" "SPI_.srec"
|
|
||||||
"E:\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-size.exe" "SPI_.elf"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Other Targets
|
|
||||||
clean:
|
|
||||||
-$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES)
|
|
||||||
-$(RM) $(C_DEPS_AS_ARGS)
|
|
||||||
rm -rf "SPI_.elf" "SPI_.a" "SPI_.hex" "SPI_.lss" "SPI_.eep" "SPI_.map" "SPI_.srec" "SPI_.usersignatures"
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
|||||||
SPIMaster.d SPIMaster.o: .././SPIMaster.c .././SPIMaster.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\io.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\inttypes.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\lib\gcc\avr\4.8.1\include\stdint.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\stdint.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\iom328p.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\portpins.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\common.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\version.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\fuse.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\lock.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\util\delay.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\util\delay_basic.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\math.h
|
|
||||||
|
|
||||||
.././SPIMaster.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\io.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\inttypes.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\lib\gcc\avr\4.8.1\include\stdint.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\stdint.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\iom328p.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\portpins.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\common.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\version.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\fuse.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\lock.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\util\delay.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\util\delay_basic.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\math.h:
|
|
Binary file not shown.
@ -1,37 +0,0 @@
|
|||||||
SPI_.d SPI_.o: .././SPI_.c \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\io.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\inttypes.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\lib\gcc\avr\4.8.1\include\stdint.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\stdint.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\iom328p.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\portpins.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\common.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\version.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\fuse.h \
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\lock.h \
|
|
||||||
.././SPIMaster.h
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\io.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\sfr_defs.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\inttypes.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\lib\gcc\avr\4.8.1\include\stdint.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\stdint.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\iom328p.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\portpins.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\common.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\version.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\fuse.h:
|
|
||||||
|
|
||||||
e:\atmel\ toolchain\avr8\ gcc\native\3.4.1061\avr8-gnu-toolchain\avr\include\avr\lock.h:
|
|
||||||
|
|
||||||
.././SPIMaster.h:
|
|
@ -1 +0,0 @@
|
|||||||
:00000001FF
|
|
Binary file not shown.
@ -1,23 +0,0 @@
|
|||||||
:100000000C9434000C9449000C9449000C94490061
|
|
||||||
:100010000C9449000C9449000C9449000C9449003C
|
|
||||||
:100020000C9449000C9449000C9449000C9449002C
|
|
||||||
:100030000C9449000C9449000C9449000C9449001C
|
|
||||||
:100040000C9449000C9449000C9449000C9449000C
|
|
||||||
:100050000C9449000C9449000C9449000C944900FC
|
|
||||||
:100060000C9449000C94490011241FBECFEFD8E036
|
|
||||||
:10007000DEBFCDBF11E0A0E0B1E0E6E4F1E002C0F8
|
|
||||||
:1000800005900D92A031B107D9F70E947D000C9424
|
|
||||||
:10009000A1000C9400008CE284B9229A82E58CBD08
|
|
||||||
:1000A00008952A98161617065CF4FC01860F971F10
|
|
||||||
:1000B00021912EBD0DB407FEFDCFE817F907C1F75A
|
|
||||||
:1000C0002A9A0895FC01680F791F80E058E040E00B
|
|
||||||
:1000D00097E00FC021918227252F342F88231CF40D
|
|
||||||
:1000E000880F892701C0880F21503109211531055A
|
|
||||||
:1000F000A9F7E617F70771F70895CF93DF93CDB708
|
|
||||||
:10010000DEB72F970FB6F894DEBF0FBECDBF0E94AB
|
|
||||||
:100110004B001FE0E0E0F1E0DE011196812F01903D
|
|
||||||
:100120000D928A95E1F76EE070E0CE0101960E9493
|
|
||||||
:1001300062008F876FE070E0CE0101960E9451004F
|
|
||||||
:06014000E9CFF894FFCFA7
|
|
||||||
:1001460004110405161218110015495059690000CA
|
|
||||||
:00000001FF
|
|
@ -1,277 +0,0 @@
|
|||||||
|
|
||||||
SPI_.elf: file format elf32-avr
|
|
||||||
|
|
||||||
Sections:
|
|
||||||
Idx Name Size VMA LMA File off Algn
|
|
||||||
0 .data 00000010 00800100 00000146 000001ba 2**0
|
|
||||||
CONTENTS, ALLOC, LOAD, DATA
|
|
||||||
1 .text 00000146 00000000 00000000 00000074 2**1
|
|
||||||
CONTENTS, ALLOC, LOAD, READONLY, CODE
|
|
||||||
2 .comment 00000030 00000000 00000000 000001ca 2**0
|
|
||||||
CONTENTS, READONLY
|
|
||||||
3 .debug_aranges 00000068 00000000 00000000 000001fa 2**0
|
|
||||||
CONTENTS, READONLY, DEBUGGING
|
|
||||||
4 .debug_info 0000039a 00000000 00000000 00000262 2**0
|
|
||||||
CONTENTS, READONLY, DEBUGGING
|
|
||||||
5 .debug_abbrev 00000275 00000000 00000000 000005fc 2**0
|
|
||||||
CONTENTS, READONLY, DEBUGGING
|
|
||||||
6 .debug_line 00000173 00000000 00000000 00000871 2**0
|
|
||||||
CONTENTS, READONLY, DEBUGGING
|
|
||||||
7 .debug_frame 000000a8 00000000 00000000 000009e4 2**2
|
|
||||||
CONTENTS, READONLY, DEBUGGING
|
|
||||||
8 .debug_str 000001ac 00000000 00000000 00000a8c 2**0
|
|
||||||
CONTENTS, READONLY, DEBUGGING
|
|
||||||
9 .debug_loc 00000303 00000000 00000000 00000c38 2**0
|
|
||||||
CONTENTS, READONLY, DEBUGGING
|
|
||||||
10 .debug_ranges 00000090 00000000 00000000 00000f3b 2**0
|
|
||||||
CONTENTS, READONLY, DEBUGGING
|
|
||||||
|
|
||||||
Disassembly of section .text:
|
|
||||||
|
|
||||||
00000000 <__vectors>:
|
|
||||||
0: 0c 94 34 00 jmp 0x68 ; 0x68 <__ctors_end>
|
|
||||||
4: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
8: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
c: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
10: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
14: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
18: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
1c: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
20: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
24: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
28: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
2c: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
30: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
34: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
38: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
3c: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
40: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
44: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
48: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
4c: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
50: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
54: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
58: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
5c: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
60: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
64: 0c 94 49 00 jmp 0x92 ; 0x92 <__bad_interrupt>
|
|
||||||
|
|
||||||
00000068 <__ctors_end>:
|
|
||||||
68: 11 24 eor r1, r1
|
|
||||||
6a: 1f be out 0x3f, r1 ; 63
|
|
||||||
6c: cf ef ldi r28, 0xFF ; 255
|
|
||||||
6e: d8 e0 ldi r29, 0x08 ; 8
|
|
||||||
70: de bf out 0x3e, r29 ; 62
|
|
||||||
72: cd bf out 0x3d, r28 ; 61
|
|
||||||
|
|
||||||
00000074 <__do_copy_data>:
|
|
||||||
74: 11 e0 ldi r17, 0x01 ; 1
|
|
||||||
76: a0 e0 ldi r26, 0x00 ; 0
|
|
||||||
78: b1 e0 ldi r27, 0x01 ; 1
|
|
||||||
7a: e6 e4 ldi r30, 0x46 ; 70
|
|
||||||
7c: f1 e0 ldi r31, 0x01 ; 1
|
|
||||||
7e: 02 c0 rjmp .+4 ; 0x84 <__do_copy_data+0x10>
|
|
||||||
80: 05 90 lpm r0, Z+
|
|
||||||
82: 0d 92 st X+, r0
|
|
||||||
84: a0 31 cpi r26, 0x10 ; 16
|
|
||||||
86: b1 07 cpc r27, r17
|
|
||||||
88: d9 f7 brne .-10 ; 0x80 <__do_copy_data+0xc>
|
|
||||||
8a: 0e 94 7d 00 call 0xfa ; 0xfa <main>
|
|
||||||
8e: 0c 94 a1 00 jmp 0x142 ; 0x142 <_exit>
|
|
||||||
|
|
||||||
00000092 <__bad_interrupt>:
|
|
||||||
92: 0c 94 00 00 jmp 0 ; 0x0 <__vectors>
|
|
||||||
|
|
||||||
00000096 <SPI_MasterInit>:
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include <util/delay.h>
|
|
||||||
|
|
||||||
void SPI_MasterInit(void)
|
|
||||||
{
|
|
||||||
DDR_SPI = (1 << DD_MOSI) | (1 << DD_SCK) | (1 << DD_SS);
|
|
||||||
96: 8c e2 ldi r24, 0x2C ; 44
|
|
||||||
98: 84 b9 out 0x04, r24 ; 4
|
|
||||||
DDRB |= (1<<DDB2);
|
|
||||||
9a: 22 9a sbi 0x04, 2 ; 4
|
|
||||||
SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1);
|
|
||||||
9c: 82 e5 ldi r24, 0x52 ; 82
|
|
||||||
9e: 8c bd out 0x2c, r24 ; 44
|
|
||||||
a0: 08 95 ret
|
|
||||||
|
|
||||||
000000a2 <SPI_MasterTransmit>:
|
|
||||||
// SPCR = (1 << SPE) | (1 << MSTR) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPI_MasterTransmit(char *data, int length)
|
|
||||||
{
|
|
||||||
PORTB &= ~(1<<2);
|
|
||||||
a2: 2a 98 cbi 0x05, 2 ; 5
|
|
||||||
|
|
||||||
for(int i = 0; i < length; i++) {
|
|
||||||
a4: 16 16 cp r1, r22
|
|
||||||
a6: 17 06 cpc r1, r23
|
|
||||||
a8: 5c f4 brge .+22 ; 0xc0 <SPI_MasterTransmit+0x1e>
|
|
||||||
aa: fc 01 movw r30, r24
|
|
||||||
ac: 86 0f add r24, r22
|
|
||||||
ae: 97 1f adc r25, r23
|
|
||||||
SPDR = data[i]; // îòïðàâëÿåì áàéò ìàññèâà
|
|
||||||
b0: 21 91 ld r18, Z+
|
|
||||||
b2: 2e bd out 0x2e, r18 ; 46
|
|
||||||
while (!(SPSR & (1 << SPIF))); // æäåì, ïîêà áàéò ïåðåäàñòñÿ
|
|
||||||
b4: 0d b4 in r0, 0x2d ; 45
|
|
||||||
b6: 07 fe sbrs r0, 7
|
|
||||||
b8: fd cf rjmp .-6 ; 0xb4 <SPI_MasterTransmit+0x12>
|
|
||||||
|
|
||||||
void SPI_MasterTransmit(char *data, int length)
|
|
||||||
{
|
|
||||||
PORTB &= ~(1<<2);
|
|
||||||
|
|
||||||
for(int i = 0; i < length; i++) {
|
|
||||||
ba: e8 17 cp r30, r24
|
|
||||||
bc: f9 07 cpc r31, r25
|
|
||||||
be: c1 f7 brne .-16 ; 0xb0 <SPI_MasterTransmit+0xe>
|
|
||||||
SPDR = data[i]; // îòïðàâëÿåì áàéò ìàññèâà
|
|
||||||
while (!(SPSR & (1 << SPIF))); // æäåì, ïîêà áàéò ïåðåäàñòñÿ
|
|
||||||
}
|
|
||||||
|
|
||||||
PORTB |= (1<<2);
|
|
||||||
c0: 2a 9a sbi 0x05, 2 ; 5
|
|
||||||
c2: 08 95 ret
|
|
||||||
|
|
||||||
000000c4 <crc8>:
|
|
||||||
}
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
char crc8(char *data, int len) {
|
|
||||||
c4: fc 01 movw r30, r24
|
|
||||||
c6: 68 0f add r22, r24
|
|
||||||
c8: 79 1f adc r23, r25
|
|
||||||
char crc = 0x00;
|
|
||||||
ca: 80 e0 ldi r24, 0x00 ; 0
|
|
||||||
while (len--) {
|
|
||||||
crc ^= *data++;
|
|
||||||
cc: 58 e0 ldi r21, 0x08 ; 8
|
|
||||||
ce: 40 e0 ldi r20, 0x00 ; 0
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
if (crc & 0x80) {
|
|
||||||
crc = (crc << 1) ^ 0x07;
|
|
||||||
d0: 97 e0 ldi r25, 0x07 ; 7
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
char crc8(char *data, int len) {
|
|
||||||
char crc = 0x00;
|
|
||||||
while (len--) {
|
|
||||||
d2: 0f c0 rjmp .+30 ; 0xf2 <crc8+0x2e>
|
|
||||||
crc ^= *data++;
|
|
||||||
d4: 21 91 ld r18, Z+
|
|
||||||
d6: 82 27 eor r24, r18
|
|
||||||
d8: 25 2f mov r18, r21
|
|
||||||
da: 34 2f mov r19, r20
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
if (crc & 0x80) {
|
|
||||||
dc: 88 23 and r24, r24
|
|
||||||
de: 1c f4 brge .+6 ; 0xe6 <crc8+0x22>
|
|
||||||
crc = (crc << 1) ^ 0x07;
|
|
||||||
e0: 88 0f add r24, r24
|
|
||||||
e2: 89 27 eor r24, r25
|
|
||||||
e4: 01 c0 rjmp .+2 ; 0xe8 <crc8+0x24>
|
|
||||||
} else {
|
|
||||||
crc <<= 1;
|
|
||||||
e6: 88 0f add r24, r24
|
|
||||||
e8: 21 50 subi r18, 0x01 ; 1
|
|
||||||
ea: 31 09 sbc r19, r1
|
|
||||||
|
|
||||||
char crc8(char *data, int len) {
|
|
||||||
char crc = 0x00;
|
|
||||||
while (len--) {
|
|
||||||
crc ^= *data++;
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
ec: 21 15 cp r18, r1
|
|
||||||
ee: 31 05 cpc r19, r1
|
|
||||||
f0: a9 f7 brne .-22 ; 0xdc <crc8+0x18>
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
char crc8(char *data, int len) {
|
|
||||||
char crc = 0x00;
|
|
||||||
while (len--) {
|
|
||||||
f2: e6 17 cp r30, r22
|
|
||||||
f4: f7 07 cpc r31, r23
|
|
||||||
f6: 71 f7 brne .-36 ; 0xd4 <crc8+0x10>
|
|
||||||
crc <<= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
f8: 08 95 ret
|
|
||||||
|
|
||||||
000000fa <main>:
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
fa: cf 93 push r28
|
|
||||||
fc: df 93 push r29
|
|
||||||
fe: cd b7 in r28, 0x3d ; 61
|
|
||||||
100: de b7 in r29, 0x3e ; 62
|
|
||||||
102: 2f 97 sbiw r28, 0x0f ; 15
|
|
||||||
104: 0f b6 in r0, 0x3f ; 63
|
|
||||||
106: f8 94 cli
|
|
||||||
108: de bf out 0x3e, r29 ; 62
|
|
||||||
10a: 0f be out 0x3f, r0 ; 63
|
|
||||||
10c: cd bf out 0x3d, r28 ; 61
|
|
||||||
// Serial.begin(9600);
|
|
||||||
SPI_MasterInit();
|
|
||||||
10e: 0e 94 4b 00 call 0x96 ; 0x96 <SPI_MasterInit>
|
|
||||||
// Serial.println("Master Initialization ");
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
char data[] = {0x04, 0x11, 0x04, 0x05, 0x16, 0x12, 0x18, 0x11, 0x00, 0x15, 0x49, 0x50, 0x59, 0x69, 0};
|
|
||||||
112: 1f e0 ldi r17, 0x0F ; 15
|
|
||||||
114: e0 e0 ldi r30, 0x00 ; 0
|
|
||||||
116: f1 e0 ldi r31, 0x01 ; 1
|
|
||||||
118: de 01 movw r26, r28
|
|
||||||
11a: 11 96 adiw r26, 0x01 ; 1
|
|
||||||
11c: 81 2f mov r24, r17
|
|
||||||
11e: 01 90 ld r0, Z+
|
|
||||||
120: 0d 92 st X+, r0
|
|
||||||
122: 8a 95 dec r24
|
|
||||||
124: e1 f7 brne .-8 ; 0x11e <main+0x24>
|
|
||||||
// Serial.println();
|
|
||||||
// Serial.print("Start: ");
|
|
||||||
// Print(data, length);
|
|
||||||
// Serial.println();
|
|
||||||
|
|
||||||
char checking = crc8(data, length-1);
|
|
||||||
126: 6e e0 ldi r22, 0x0E ; 14
|
|
||||||
128: 70 e0 ldi r23, 0x00 ; 0
|
|
||||||
12a: ce 01 movw r24, r28
|
|
||||||
12c: 01 96 adiw r24, 0x01 ; 1
|
|
||||||
12e: 0e 94 62 00 call 0xc4 ; 0xc4 <crc8>
|
|
||||||
int size = sizeof(data) / sizeof(data[0]);
|
|
||||||
data[size - 1] = checking;
|
|
||||||
132: 8f 87 std Y+15, r24 ; 0x0f
|
|
||||||
|
|
||||||
// Serial.print("End: ");
|
|
||||||
// Print(data, length);
|
|
||||||
// Serial.println();
|
|
||||||
|
|
||||||
SPI_MasterTransmit(data, length);
|
|
||||||
134: 6f e0 ldi r22, 0x0F ; 15
|
|
||||||
136: 70 e0 ldi r23, 0x00 ; 0
|
|
||||||
138: ce 01 movw r24, r28
|
|
||||||
13a: 01 96 adiw r24, 0x01 ; 1
|
|
||||||
13c: 0e 94 51 00 call 0xa2 ; 0xa2 <SPI_MasterTransmit>
|
|
||||||
140: e9 cf rjmp .-46 ; 0x114 <main+0x1a>
|
|
||||||
|
|
||||||
00000142 <_exit>:
|
|
||||||
142: f8 94 cli
|
|
||||||
|
|
||||||
00000144 <__stop_program>:
|
|
||||||
144: ff cf rjmp .-2 ; 0x144 <__stop_program>
|
|
@ -1,446 +0,0 @@
|
|||||||
Archive member included because of file (symbol)
|
|
||||||
|
|
||||||
e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5/crtm328p.o (exit)
|
|
||||||
e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
SPI_.o (__do_copy_data)
|
|
||||||
|
|
||||||
Discarded input sections
|
|
||||||
|
|
||||||
.data 0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5/crtm328p.o
|
|
||||||
.bss 0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5/crtm328p.o
|
|
||||||
.text 0x00000000 0x0 SPIMaster.o
|
|
||||||
.data 0x00000000 0x0 SPIMaster.o
|
|
||||||
.bss 0x00000000 0x0 SPIMaster.o
|
|
||||||
.text.CRC8 0x00000000 0x44 SPIMaster.o
|
|
||||||
.text 0x00000000 0x0 SPI_.o
|
|
||||||
.data 0x00000000 0x0 SPI_.o
|
|
||||||
.bss 0x00000000 0x0 SPI_.o
|
|
||||||
.text.Print 0x00000000 0x14 SPI_.o
|
|
||||||
.text.setup 0x00000000 0x2 SPI_.o
|
|
||||||
.text 0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
.data 0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
.bss 0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
.text.libgcc.mul
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
.text.libgcc.div
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
.text.libgcc 0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
.text.libgcc.prologue
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
.text.libgcc.builtins
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
.text.libgcc.fmul
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
.text.libgcc.fixed
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
.text 0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
.data 0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
.bss 0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
.text.libgcc.mul
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
.text.libgcc.div
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
.text.libgcc 0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
.text.libgcc.prologue
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
.text.libgcc.builtins
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
.text.libgcc.fmul
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
.text.libgcc.fixed
|
|
||||||
0x00000000 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
|
|
||||||
Memory Configuration
|
|
||||||
|
|
||||||
Name Origin Length Attributes
|
|
||||||
text 0x00000000 0x00020000 xr
|
|
||||||
data 0x00800060 0x0000ffa0 rw !x
|
|
||||||
eeprom 0x00810000 0x00010000 rw !x
|
|
||||||
fuse 0x00820000 0x00000400 rw !x
|
|
||||||
lock 0x00830000 0x00000400 rw !x
|
|
||||||
signature 0x00840000 0x00000400 rw !x
|
|
||||||
user_signatures 0x00850000 0x00000400 rw !x
|
|
||||||
*default* 0x00000000 0xffffffff
|
|
||||||
|
|
||||||
Linker script and memory map
|
|
||||||
|
|
||||||
Address of section .data set to 0x800100
|
|
||||||
LOAD e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5/crtm328p.o
|
|
||||||
LOAD SPIMaster.o
|
|
||||||
LOAD SPI_.o
|
|
||||||
START GROUP
|
|
||||||
LOAD e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5\libm.a
|
|
||||||
END GROUP
|
|
||||||
START GROUP
|
|
||||||
LOAD e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a
|
|
||||||
LOAD e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5\libm.a
|
|
||||||
LOAD e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5\libc.a
|
|
||||||
END GROUP
|
|
||||||
|
|
||||||
.hash
|
|
||||||
*(.hash)
|
|
||||||
|
|
||||||
.dynsym
|
|
||||||
*(.dynsym)
|
|
||||||
|
|
||||||
.dynstr
|
|
||||||
*(.dynstr)
|
|
||||||
|
|
||||||
.gnu.version
|
|
||||||
*(.gnu.version)
|
|
||||||
|
|
||||||
.gnu.version_d
|
|
||||||
*(.gnu.version_d)
|
|
||||||
|
|
||||||
.gnu.version_r
|
|
||||||
*(.gnu.version_r)
|
|
||||||
|
|
||||||
.rel.init
|
|
||||||
*(.rel.init)
|
|
||||||
|
|
||||||
.rela.init
|
|
||||||
*(.rela.init)
|
|
||||||
|
|
||||||
.rel.text
|
|
||||||
*(.rel.text)
|
|
||||||
*(.rel.text.*)
|
|
||||||
*(.rel.gnu.linkonce.t*)
|
|
||||||
|
|
||||||
.rela.text
|
|
||||||
*(.rela.text)
|
|
||||||
*(.rela.text.*)
|
|
||||||
*(.rela.gnu.linkonce.t*)
|
|
||||||
|
|
||||||
.rel.fini
|
|
||||||
*(.rel.fini)
|
|
||||||
|
|
||||||
.rela.fini
|
|
||||||
*(.rela.fini)
|
|
||||||
|
|
||||||
.rel.rodata
|
|
||||||
*(.rel.rodata)
|
|
||||||
*(.rel.rodata.*)
|
|
||||||
*(.rel.gnu.linkonce.r*)
|
|
||||||
|
|
||||||
.rela.rodata
|
|
||||||
*(.rela.rodata)
|
|
||||||
*(.rela.rodata.*)
|
|
||||||
*(.rela.gnu.linkonce.r*)
|
|
||||||
|
|
||||||
.rel.data
|
|
||||||
*(.rel.data)
|
|
||||||
*(.rel.data.*)
|
|
||||||
*(.rel.gnu.linkonce.d*)
|
|
||||||
|
|
||||||
.rela.data
|
|
||||||
*(.rela.data)
|
|
||||||
*(.rela.data.*)
|
|
||||||
*(.rela.gnu.linkonce.d*)
|
|
||||||
|
|
||||||
.rel.ctors
|
|
||||||
*(.rel.ctors)
|
|
||||||
|
|
||||||
.rela.ctors
|
|
||||||
*(.rela.ctors)
|
|
||||||
|
|
||||||
.rel.dtors
|
|
||||||
*(.rel.dtors)
|
|
||||||
|
|
||||||
.rela.dtors
|
|
||||||
*(.rela.dtors)
|
|
||||||
|
|
||||||
.rel.got
|
|
||||||
*(.rel.got)
|
|
||||||
|
|
||||||
.rela.got
|
|
||||||
*(.rela.got)
|
|
||||||
|
|
||||||
.rel.bss
|
|
||||||
*(.rel.bss)
|
|
||||||
|
|
||||||
.rela.bss
|
|
||||||
*(.rela.bss)
|
|
||||||
|
|
||||||
.rel.plt
|
|
||||||
*(.rel.plt)
|
|
||||||
|
|
||||||
.rela.plt
|
|
||||||
*(.rela.plt)
|
|
||||||
|
|
||||||
.text 0x00000000 0x146
|
|
||||||
*(.vectors)
|
|
||||||
.vectors 0x00000000 0x68 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5/crtm328p.o
|
|
||||||
0x00000000 __vector_default
|
|
||||||
0x00000000 __vectors
|
|
||||||
*(.vectors)
|
|
||||||
*(.progmem.gcc*)
|
|
||||||
0x00000068 . = ALIGN (0x2)
|
|
||||||
0x00000068 __trampolines_start = .
|
|
||||||
*(.trampolines)
|
|
||||||
.trampolines 0x00000068 0x0 linker stubs
|
|
||||||
*(.trampolines*)
|
|
||||||
0x00000068 __trampolines_end = .
|
|
||||||
*(.progmem*)
|
|
||||||
0x00000068 . = ALIGN (0x2)
|
|
||||||
*(.jumptables)
|
|
||||||
*(.jumptables*)
|
|
||||||
*(.lowtext)
|
|
||||||
*(.lowtext*)
|
|
||||||
0x00000068 __ctors_start = .
|
|
||||||
*(.ctors)
|
|
||||||
0x00000068 __ctors_end = .
|
|
||||||
0x00000068 __dtors_start = .
|
|
||||||
*(.dtors)
|
|
||||||
0x00000068 __dtors_end = .
|
|
||||||
SORT(*)(.ctors)
|
|
||||||
SORT(*)(.dtors)
|
|
||||||
*(.init0)
|
|
||||||
.init0 0x00000068 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5/crtm328p.o
|
|
||||||
0x00000068 __init
|
|
||||||
*(.init0)
|
|
||||||
*(.init1)
|
|
||||||
*(.init1)
|
|
||||||
*(.init2)
|
|
||||||
.init2 0x00000068 0xc e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5/crtm328p.o
|
|
||||||
*(.init2)
|
|
||||||
*(.init3)
|
|
||||||
*(.init3)
|
|
||||||
*(.init4)
|
|
||||||
.init4 0x00000074 0x16 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_copy_data.o)
|
|
||||||
0x00000074 __do_copy_data
|
|
||||||
*(.init4)
|
|
||||||
*(.init5)
|
|
||||||
*(.init5)
|
|
||||||
*(.init6)
|
|
||||||
*(.init6)
|
|
||||||
*(.init7)
|
|
||||||
*(.init7)
|
|
||||||
*(.init8)
|
|
||||||
*(.init8)
|
|
||||||
*(.init9)
|
|
||||||
.init9 0x0000008a 0x8 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5/crtm328p.o
|
|
||||||
*(.init9)
|
|
||||||
*(.text)
|
|
||||||
.text 0x00000092 0x4 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/avr5/crtm328p.o
|
|
||||||
0x00000092 __vector_22
|
|
||||||
0x00000092 __vector_1
|
|
||||||
0x00000092 __vector_24
|
|
||||||
0x00000092 __vector_12
|
|
||||||
0x00000092 __bad_interrupt
|
|
||||||
0x00000092 __vector_6
|
|
||||||
0x00000092 __vector_3
|
|
||||||
0x00000092 __vector_23
|
|
||||||
0x00000092 __vector_25
|
|
||||||
0x00000092 __vector_11
|
|
||||||
0x00000092 __vector_13
|
|
||||||
0x00000092 __vector_17
|
|
||||||
0x00000092 __vector_19
|
|
||||||
0x00000092 __vector_7
|
|
||||||
0x00000092 __vector_5
|
|
||||||
0x00000092 __vector_4
|
|
||||||
0x00000092 __vector_9
|
|
||||||
0x00000092 __vector_2
|
|
||||||
0x00000092 __vector_21
|
|
||||||
0x00000092 __vector_15
|
|
||||||
0x00000092 __vector_8
|
|
||||||
0x00000092 __vector_14
|
|
||||||
0x00000092 __vector_10
|
|
||||||
0x00000092 __vector_16
|
|
||||||
0x00000092 __vector_18
|
|
||||||
0x00000092 __vector_20
|
|
||||||
0x00000096 . = ALIGN (0x2)
|
|
||||||
*(.text.*)
|
|
||||||
.text.SPI_MasterInit
|
|
||||||
0x00000096 0xc SPIMaster.o
|
|
||||||
0x00000096 SPI_MasterInit
|
|
||||||
.text.SPI_MasterTransmit
|
|
||||||
0x000000a2 0x22 SPIMaster.o
|
|
||||||
0x000000a2 SPI_MasterTransmit
|
|
||||||
.text.crc8 0x000000c4 0x36 SPIMaster.o
|
|
||||||
0x000000c4 crc8
|
|
||||||
.text.main 0x000000fa 0x48 SPI_.o
|
|
||||||
0x000000fa main
|
|
||||||
0x00000142 . = ALIGN (0x2)
|
|
||||||
*(.fini9)
|
|
||||||
.fini9 0x00000142 0x0 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
0x00000142 _exit
|
|
||||||
0x00000142 exit
|
|
||||||
*(.fini9)
|
|
||||||
*(.fini8)
|
|
||||||
*(.fini8)
|
|
||||||
*(.fini7)
|
|
||||||
*(.fini7)
|
|
||||||
*(.fini6)
|
|
||||||
*(.fini6)
|
|
||||||
*(.fini5)
|
|
||||||
*(.fini5)
|
|
||||||
*(.fini4)
|
|
||||||
*(.fini4)
|
|
||||||
*(.fini3)
|
|
||||||
*(.fini3)
|
|
||||||
*(.fini2)
|
|
||||||
*(.fini2)
|
|
||||||
*(.fini1)
|
|
||||||
*(.fini1)
|
|
||||||
*(.fini0)
|
|
||||||
.fini0 0x00000142 0x4 e:/atmel toolchain/avr8 gcc/native/3.4.1061/avr8-gnu-toolchain/bin/../lib/gcc/avr/4.8.1/avr5\libgcc.a(_exit.o)
|
|
||||||
*(.fini0)
|
|
||||||
0x00000146 _etext = .
|
|
||||||
|
|
||||||
.data 0x00800100 0x10 load address 0x00000146
|
|
||||||
0x00800100 PROVIDE (__data_start, .)
|
|
||||||
*(.data)
|
|
||||||
*(.data*)
|
|
||||||
*(.rodata)
|
|
||||||
.rodata 0x00800100 0xf SPI_.o
|
|
||||||
*(.rodata*)
|
|
||||||
*(.gnu.linkonce.d*)
|
|
||||||
0x00800110 . = ALIGN (0x2)
|
|
||||||
*fill* 0x0080010f 0x1
|
|
||||||
0x00800110 _edata = .
|
|
||||||
0x00800110 PROVIDE (__data_end, .)
|
|
||||||
|
|
||||||
.bss 0x00800110 0x0
|
|
||||||
0x00800110 PROVIDE (__bss_start, .)
|
|
||||||
*(.bss)
|
|
||||||
*(.bss*)
|
|
||||||
*(COMMON)
|
|
||||||
0x00800110 PROVIDE (__bss_end, .)
|
|
||||||
0x00000146 __data_load_start = LOADADDR (.data)
|
|
||||||
0x00000156 __data_load_end = (__data_load_start + SIZEOF (.data))
|
|
||||||
|
|
||||||
.noinit 0x00800110 0x0
|
|
||||||
0x00800110 PROVIDE (__noinit_start, .)
|
|
||||||
*(.noinit*)
|
|
||||||
0x00800110 PROVIDE (__noinit_end, .)
|
|
||||||
0x00800110 _end = .
|
|
||||||
0x00800110 PROVIDE (__heap_start, .)
|
|
||||||
|
|
||||||
.eeprom 0x00810000 0x0
|
|
||||||
*(.eeprom*)
|
|
||||||
0x00810000 __eeprom_end = .
|
|
||||||
|
|
||||||
.fuse
|
|
||||||
*(.fuse)
|
|
||||||
*(.lfuse)
|
|
||||||
*(.hfuse)
|
|
||||||
*(.efuse)
|
|
||||||
|
|
||||||
.lock
|
|
||||||
*(.lock*)
|
|
||||||
|
|
||||||
.signature
|
|
||||||
*(.signature*)
|
|
||||||
|
|
||||||
.user_signatures
|
|
||||||
*(.user_signatures*)
|
|
||||||
|
|
||||||
.stab
|
|
||||||
*(.stab)
|
|
||||||
|
|
||||||
.stabstr
|
|
||||||
*(.stabstr)
|
|
||||||
|
|
||||||
.stab.excl
|
|
||||||
*(.stab.excl)
|
|
||||||
|
|
||||||
.stab.exclstr
|
|
||||||
*(.stab.exclstr)
|
|
||||||
|
|
||||||
.stab.index
|
|
||||||
*(.stab.index)
|
|
||||||
|
|
||||||
.stab.indexstr
|
|
||||||
*(.stab.indexstr)
|
|
||||||
|
|
||||||
.comment 0x00000000 0x30
|
|
||||||
*(.comment)
|
|
||||||
.comment 0x00000000 0x30 SPIMaster.o
|
|
||||||
0x31 (size before relaxing)
|
|
||||||
.comment 0x00000000 0x31 SPI_.o
|
|
||||||
|
|
||||||
.note.gnu.build-id
|
|
||||||
*(.note.gnu.build-id)
|
|
||||||
|
|
||||||
.debug
|
|
||||||
*(.debug)
|
|
||||||
|
|
||||||
.line
|
|
||||||
*(.line)
|
|
||||||
|
|
||||||
.debug_srcinfo
|
|
||||||
*(.debug_srcinfo)
|
|
||||||
|
|
||||||
.debug_sfnames
|
|
||||||
*(.debug_sfnames)
|
|
||||||
|
|
||||||
.debug_aranges 0x00000000 0x68
|
|
||||||
*(.debug_aranges)
|
|
||||||
.debug_aranges
|
|
||||||
0x00000000 0x38 SPIMaster.o
|
|
||||||
.debug_aranges
|
|
||||||
0x00000038 0x30 SPI_.o
|
|
||||||
|
|
||||||
.debug_pubnames
|
|
||||||
*(.debug_pubnames)
|
|
||||||
|
|
||||||
.debug_info 0x00000000 0x39a
|
|
||||||
*(.debug_info .gnu.linkonce.wi.*)
|
|
||||||
.debug_info 0x00000000 0x1bf SPIMaster.o
|
|
||||||
.debug_info 0x000001bf 0x1db SPI_.o
|
|
||||||
|
|
||||||
.debug_abbrev 0x00000000 0x275
|
|
||||||
*(.debug_abbrev)
|
|
||||||
.debug_abbrev 0x00000000 0x105 SPIMaster.o
|
|
||||||
.debug_abbrev 0x00000105 0x170 SPI_.o
|
|
||||||
|
|
||||||
.debug_line 0x00000000 0x173
|
|
||||||
*(.debug_line .debug_line.* .debug_line_end)
|
|
||||||
.debug_line 0x00000000 0xee SPIMaster.o
|
|
||||||
.debug_line 0x000000ee 0x85 SPI_.o
|
|
||||||
|
|
||||||
.debug_frame 0x00000000 0xa8
|
|
||||||
*(.debug_frame)
|
|
||||||
.debug_frame 0x00000000 0x54 SPIMaster.o
|
|
||||||
.debug_frame 0x00000054 0x54 SPI_.o
|
|
||||||
|
|
||||||
.debug_str 0x00000000 0x1ac
|
|
||||||
*(.debug_str)
|
|
||||||
.debug_str 0x00000000 0x16b SPIMaster.o
|
|
||||||
0x1a4 (size before relaxing)
|
|
||||||
.debug_str 0x0000016b 0x41 SPI_.o
|
|
||||||
0x1c2 (size before relaxing)
|
|
||||||
|
|
||||||
.debug_loc 0x00000000 0x303
|
|
||||||
*(.debug_loc)
|
|
||||||
.debug_loc 0x00000000 0x253 SPIMaster.o
|
|
||||||
.debug_loc 0x00000253 0xb0 SPI_.o
|
|
||||||
|
|
||||||
.debug_macinfo
|
|
||||||
*(.debug_macinfo)
|
|
||||||
|
|
||||||
.debug_weaknames
|
|
||||||
*(.debug_weaknames)
|
|
||||||
|
|
||||||
.debug_funcnames
|
|
||||||
*(.debug_funcnames)
|
|
||||||
|
|
||||||
.debug_typenames
|
|
||||||
*(.debug_typenames)
|
|
||||||
|
|
||||||
.debug_varnames
|
|
||||||
*(.debug_varnames)
|
|
||||||
|
|
||||||
.debug_pubtypes
|
|
||||||
*(.debug_pubtypes)
|
|
||||||
|
|
||||||
.debug_ranges 0x00000000 0x90
|
|
||||||
*(.debug_ranges)
|
|
||||||
.debug_ranges 0x00000000 0x70 SPIMaster.o
|
|
||||||
.debug_ranges 0x00000070 0x20 SPI_.o
|
|
||||||
|
|
||||||
.debug_macro
|
|
||||||
*(.debug_macro)
|
|
||||||
OUTPUT(SPI_.elf elf32-avr)
|
|
||||||
LOAD linker stubs
|
|
Binary file not shown.
@ -1,24 +0,0 @@
|
|||||||
S00C00005350495F2E73726563CD
|
|
||||||
S11300000C9434000C9449000C9449000C9449005D
|
|
||||||
S11300100C9449000C9449000C9449000C94490038
|
|
||||||
S11300200C9449000C9449000C9449000C94490028
|
|
||||||
S11300300C9449000C9449000C9449000C94490018
|
|
||||||
S11300400C9449000C9449000C9449000C94490008
|
|
||||||
S11300500C9449000C9449000C9449000C944900F8
|
|
||||||
S11300600C9449000C94490011241FBECFEFD8E032
|
|
||||||
S1130070DEBFCDBF11E0A0E0B1E0E6E4F1E002C0F4
|
|
||||||
S113008005900D92A031B107D9F70E947D000C9420
|
|
||||||
S1130090A1000C9400008CE284B9229A82E58CBD04
|
|
||||||
S11300A008952A98161617065CF4FC01860F971F0C
|
|
||||||
S11300B021912EBD0DB407FEFDCFE817F907C1F756
|
|
||||||
S11300C02A9A0895FC01680F791F80E058E040E007
|
|
||||||
S11300D097E00FC021918227252F342F88231CF409
|
|
||||||
S11300E0880F892701C0880F215031092115310556
|
|
||||||
S11300F0A9F7E617F70771F70895CF93DF93CDB704
|
|
||||||
S1130100DEB72F970FB6F894DEBF0FBECDBF0E94A7
|
|
||||||
S11301104B001FE0E0E0F1E0DE011196812F019039
|
|
||||||
S11301200D928A95E1F76EE070E0CE0101960E948F
|
|
||||||
S113013062008F876FE070E0CE0101960E9451004B
|
|
||||||
S1090140E9CFF894FFCFA3
|
|
||||||
S113014604110405161218110015495059690000C6
|
|
||||||
S9030000FC
|
|
@ -1,8 +0,0 @@
|
|||||||
################################################################################
|
|
||||||
# Automatically-generated file. Do not edit or delete the file
|
|
||||||
################################################################################
|
|
||||||
|
|
||||||
SPIMaster.c
|
|
||||||
|
|
||||||
SPI_.c
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPIMaster.c
|
|
||||||
*
|
|
||||||
* Created: 22.05.2023 14:36:51
|
|
||||||
* Author: asus
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "SPIMaster.h"
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include <util/delay.h>
|
|
||||||
|
|
||||||
void SPI_MasterInit(void)
|
|
||||||
{
|
|
||||||
DDR_SPI = (1 << DD_MOSI) | (1 << DD_SCK) | (1 << DD_SS);
|
|
||||||
DDRB |= (1<<DDB2);
|
|
||||||
SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1);
|
|
||||||
// SPCR = (1 << SPE) | (1 << MSTR) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPI_MasterTransmit(char *data, int length)
|
|
||||||
{
|
|
||||||
PORTB &= ~(1<<2);
|
|
||||||
|
|
||||||
for(int i = 0; i < length; i++) {
|
|
||||||
SPDR = data[i]; // îòïðàâëÿåì áàéò ìàññèâà
|
|
||||||
while (!(SPSR & (1 << SPIF))); // æäåì, ïîêà áàéò ïåðåäàñòñÿ
|
|
||||||
}
|
|
||||||
|
|
||||||
PORTB |= (1<<2);
|
|
||||||
}
|
|
||||||
|
|
||||||
char CRC8(char *data, int length) {
|
|
||||||
char crc = 0x00;
|
|
||||||
char poly = 0x07; // ïîëèíîì äëÿ CRC8
|
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
crc ^= data[i]; // XOR òåêóùåãî áàéòà ñ crc
|
|
||||||
|
|
||||||
for (int j = 0; j < length; j++) {
|
|
||||||
if (crc & 0x80) { // åñëè ñòàðøèé áèò crc ðàâåí 1
|
|
||||||
crc = (crc << 1) ^ poly; // ñäâèãàåì crc íà 1 áèò âëåâî è XOR ñ ïîëèíîìîì
|
|
||||||
} else {
|
|
||||||
crc <<= 1; // èíà÷å ïðîñòî ñäâèãàåì íà 1 áèò âëåâî
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
char crc8(char *data, int len) {
|
|
||||||
char crc = 0x00;
|
|
||||||
while (len--) {
|
|
||||||
crc ^= *data++;
|
|
||||||
for (int i = 0; i < 8; i++) {
|
|
||||||
if (crc & 0x80) {
|
|
||||||
crc = (crc << 1) ^ 0x07;
|
|
||||||
} else {
|
|
||||||
crc <<= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return crc;
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPIMaster.h
|
|
||||||
*
|
|
||||||
* Created: 22.05.2023 14:36:20
|
|
||||||
* Author: asus
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SPIMaster_h
|
|
||||||
#define SPIMaster_h
|
|
||||||
|
|
||||||
#define DDR_SPI DDRB
|
|
||||||
#define DD_MOSI PB3
|
|
||||||
#define DD_MISO PB4
|
|
||||||
#define DD_SCK PB5
|
|
||||||
#define DD_SS PB2
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SPI_MasterInit(void);
|
|
||||||
void SPI_MasterTransmit(char *data, int length);
|
|
||||||
char CRC8(char *data, int length);
|
|
||||||
char crc8(char *data, int len);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
* SPI_.c
|
|
||||||
*
|
|
||||||
* Created: 22.05.2023 14:31:15
|
|
||||||
* Author: asus
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <avr/io.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include "SPIMaster.h"
|
|
||||||
|
|
||||||
|
|
||||||
void Print(char *data2, int lenght){
|
|
||||||
for(int i = 0; i < lenght; i++) {
|
|
||||||
// Serial.print(data2[i], HEX);
|
|
||||||
// Serial.print(" ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int printf( const char * format, ... )
|
|
||||||
{
|
|
||||||
char buffer[16];
|
|
||||||
va_list args;
|
|
||||||
va_start (args, format);
|
|
||||||
size_t s = vsprintf (buffer,format, args);
|
|
||||||
for(size_t i = 0; i < s; i++){
|
|
||||||
while (!(UCSR0A & (1<<UDREn)));
|
|
||||||
UDR0 = buffer[i];
|
|
||||||
}
|
|
||||||
va_end (args);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
// Serial.begin(9600);
|
|
||||||
SPI_MasterInit();
|
|
||||||
printf("MAster Init .....");
|
|
||||||
// Serial.println("Master Initialization ");
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
char data[] = {0x04, 0x11, 0x04, 0x05, 0x16, 0x12, 0x18, 0x11, 0x00, 0x15, 0x49, 0x50, 0x59, 0x69, 0};
|
|
||||||
int length = sizeof(data);
|
|
||||||
printf(data);
|
|
||||||
// Serial.println();
|
|
||||||
// Serial.print("Start: ");
|
|
||||||
// Print(data, length);
|
|
||||||
// Serial.println();
|
|
||||||
|
|
||||||
char checking = crc8(data, length-1);
|
|
||||||
int size = sizeof(data) / sizeof(data[0]);
|
|
||||||
data[size - 1] = checking;
|
|
||||||
// Serial.println(checking, HEX);
|
|
||||||
|
|
||||||
// Serial.print("End: ");
|
|
||||||
// Print(data, length);
|
|
||||||
// Serial.println();
|
|
||||||
|
|
||||||
SPI_MasterTransmit(data, length);
|
|
||||||
// delay(1000);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,110 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
|
||||||
<ProjectVersion>6.2</ProjectVersion>
|
|
||||||
<ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
|
|
||||||
<ProjectGuid>{37275dfd-0ce5-467a-9f25-7a9e49ff51c2}</ProjectGuid>
|
|
||||||
<avrdevice>ATmega328P</avrdevice>
|
|
||||||
<avrdeviceseries>none</avrdeviceseries>
|
|
||||||
<OutputType>Executable</OutputType>
|
|
||||||
<Language>C</Language>
|
|
||||||
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
|
||||||
<OutputFileExtension>.elf</OutputFileExtension>
|
|
||||||
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
|
||||||
<AssemblyName>SPI_</AssemblyName>
|
|
||||||
<Name>SPI_</Name>
|
|
||||||
<RootNamespace>SPI_</RootNamespace>
|
|
||||||
<ToolchainFlavour>Native</ToolchainFlavour>
|
|
||||||
<KeepTimersRunning>true</KeepTimersRunning>
|
|
||||||
<OverrideVtor>false</OverrideVtor>
|
|
||||||
<CacheFlash>true</CacheFlash>
|
|
||||||
<ProgFlashFromRam>true</ProgFlashFromRam>
|
|
||||||
<RamSnippetAddress />
|
|
||||||
<UncachedRange />
|
|
||||||
<preserveEEPROM>true</preserveEEPROM>
|
|
||||||
<OverrideVtorValue />
|
|
||||||
<BootSegment>2</BootSegment>
|
|
||||||
<eraseonlaunchrule>1</eraseonlaunchrule>
|
|
||||||
<AsfFrameworkConfig>
|
|
||||||
<framework-data xmlns="">
|
|
||||||
<options />
|
|
||||||
<configurations />
|
|
||||||
<files />
|
|
||||||
<documentation help="" />
|
|
||||||
<offline-documentation help="" />
|
|
||||||
<dependencies>
|
|
||||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.21.0" />
|
|
||||||
</dependencies>
|
|
||||||
</framework-data>
|
|
||||||
</AsfFrameworkConfig>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
|
||||||
<ToolchainSettings>
|
|
||||||
<AvrGcc>
|
|
||||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
|
||||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
|
||||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
|
||||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
|
||||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
|
||||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
|
||||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
|
||||||
<avrgcc.compiler.symbols.DefSymbols>
|
|
||||||
<ListValues>
|
|
||||||
<Value>NDEBUG</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcc.compiler.symbols.DefSymbols>
|
|
||||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
|
||||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
|
||||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
|
||||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
|
||||||
<avrgcc.linker.libraries.Libraries>
|
|
||||||
<ListValues>
|
|
||||||
<Value>libm</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcc.linker.libraries.Libraries>
|
|
||||||
</AvrGcc>
|
|
||||||
</ToolchainSettings>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
|
||||||
<ToolchainSettings>
|
|
||||||
<AvrGcc>
|
|
||||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
|
||||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
|
||||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
|
||||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
|
||||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
|
||||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
|
||||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
|
||||||
<avrgcc.compiler.symbols.DefSymbols>
|
|
||||||
<ListValues>
|
|
||||||
<Value>DEBUG</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcc.compiler.symbols.DefSymbols>
|
|
||||||
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
|
||||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
|
||||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
|
||||||
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
|
|
||||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
|
||||||
<avrgcc.linker.libraries.Libraries>
|
|
||||||
<ListValues>
|
|
||||||
<Value>libm</Value>
|
|
||||||
</ListValues>
|
|
||||||
</avrgcc.linker.libraries.Libraries>
|
|
||||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
|
||||||
</AvrGcc>
|
|
||||||
</ToolchainSettings>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="SPIMaster.c">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="SPIMaster.h">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Include="SPI_.c">
|
|
||||||
<SubType>compile</SubType>
|
|
||||||
</Compile>
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
|
||||||
</Project>
|
|
211
protocol.md
Normal file
211
protocol.md
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
# Передача команды и параметров по шине SPI
|
||||||
|
|
||||||
|
При передаче пакета
|
||||||
|
1) Byte команды.
|
||||||
|
2) Byte[] массив параметров.
|
||||||
|
3) Byte контрольной суммы.
|
||||||
|
|
||||||
|
# Команды:
|
||||||
|
|
||||||
|
Условные обозначения:
|
||||||
|
|Обозначение|Описание|
|
||||||
|
|:-:|-|
|
||||||
|
|\||ИЛИ (значение слева или значение справа)|
|
||||||
|
|a<sub>1</sub>, a<sub>2</sub> , ..., a<sub>n</sub>|Диапазон (одно значение из диапазона)|
|
||||||
|
|\[...]|Несколько подобных значений|
|
||||||
|
|СxRC|Байт контрольной суммы|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Заполнение экрана белым или черным цветом
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x01
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|Color|
|
||||||
|
|-|
|
||||||
|
|0x00\|0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|Color|Описание|Полная команда|
|
||||||
|
|-|-|-|
|
||||||
|
|0x00|Заполнить экран черными пикселями|0x01 0x00 CxRC|
|
||||||
|
|0x01|Заполнить экран белыми пикселями|0x01 0x01 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Выбор строки на экране
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x02
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|Page|
|
||||||
|
|-|
|
||||||
|
|0x00,0x01,...,0x07|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|Page|Описание|Полная команда|
|
||||||
|
|-|-|-|
|
||||||
|
|0x03|Выбрать 3 строку|0x02 0x03 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Добавление нового символа
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x03
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|Symbols|
|
||||||
|
|-|
|
||||||
|
|[0x01,0x02,...,0x16]|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|Symbols|Описание|Полная команда|
|
||||||
|
|-|-|-|
|
||||||
|
|0x0e 0x10|Добавить символы 5 и 7|0x03 0x0e 0x10 CxRC|
|
||||||
|
|
||||||
|
**Описание:**
|
||||||
|
|
||||||
|
" " - 0x00
|
||||||
|
"(" - 0x01
|
||||||
|
")" - 0x02
|
||||||
|
"*" - 0x03
|
||||||
|
"+" - 0x04
|
||||||
|
"," - 0x05
|
||||||
|
"-" - 0x06
|
||||||
|
"." - 0x07
|
||||||
|
"/" - 0x08
|
||||||
|
"0" - 0x09
|
||||||
|
"1" - 0x0a
|
||||||
|
"2" - 0x0b
|
||||||
|
"3" - 0x0c
|
||||||
|
"4" - 0x0d
|
||||||
|
"5" - 0x0e
|
||||||
|
"6" - 0x0f
|
||||||
|
"7" - 0x10
|
||||||
|
"8" - 0x11
|
||||||
|
"9" - 0x12
|
||||||
|
":" - 0x13
|
||||||
|
"<" - 0x14
|
||||||
|
"=" - 0x15
|
||||||
|
">" - 0x16
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Удаление символов
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x04
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|Amount|
|
||||||
|
|-|
|
||||||
|
|0x01,0x02,...,0xFF|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|Amount|Описание|Полная команда|
|
||||||
|
|-|-|-|
|
||||||
|
|0x40|Удалить 64 символа|0x04 0x40 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Поставить пиксель белого или черного цвета по координатах
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x05
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|X|Y|Color|
|
||||||
|
|-|-|-|
|
||||||
|
|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x00 \| 0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|X|Y|Color|Описание|Полная команда|
|
||||||
|
|-|-|-|-|-|
|
||||||
|
|0x24|0x04|0x01|Поставить белый пиксель в координатах x-36; y-4|0x05 0x24 0x04 0x01 CxRC|
|
||||||
|
|0x0B|0x16|0x00|Поставить черный пиксель в координатах x-11; y-22|0x05 0x0B 0x16 0x00 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Нарисовать линию по координатам, белого или черного цвета
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x06
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|X|Y|X2|Y2|Color|
|
||||||
|
|-|-|-|-|-|
|
||||||
|
|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x00 \| 0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|X|Y|X2|Y2|Color|Описание|Полная команда|
|
||||||
|
|-|-|-|-|-|-|-|
|
||||||
|
|0x02|0x02|0x05|0x05|0x01|Нарисовать линию белого цвета в координатах: начало x-2 , y-2; конец x-5, y-5 |0x06 0x02 0x02 0x05 0x05 0x01 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Нарисовать круг белого или черного цвета по координатам и радиусу
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x07
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|X|Y|R|Color|Fill|
|
||||||
|
|-|-|-|-|-|
|
||||||
|
|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x01,0x02,...,0xFF| 0x00 \| 0x01| 0x00 \| 0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|X|Y|R|Color|Fill|Описание|Полная команда|
|
||||||
|
|-|-|-|-|-|-|-|
|
||||||
|
|0x03|0x09|0x05|0x01|0x01|Нарисовать заполненный белый круг c координатами центра x-3, y-9 и радиусом 5|0x07 0x03 0x09 0x05 0x01 0x01 CxRC
|
||||||
|
|0x03|0x09|0x05|0x01|0x00|Нарисовать не заполненный белый круг c координатами центра x-3, y-9 и радиусом 5|0x07 0x03 0x09 0x05 0x01 0x00 CxRC|
|
||||||
|
|0x03|0x09|0x05|0x00|0x01|Нарисовать заполненный черный круг c координатами центра x-3, y-9 и радиусом 5|0x07 0x03 0x09 0x05 0x00 0x01 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Нарисовать прямоугольник белого или черного цвета по координатам
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x08
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|X|Y|Widht|Height|Color|Fill|
|
||||||
|
|-|-|-|-|-|-|
|
||||||
|
|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x00,0x01, … ,0x10| 0x00 \| 0x01| 0x00 \| 0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|X|Y|Widht|Height|Color|Fill|Описание|Полная команда|
|
||||||
|
|-|-|-|-|-|-|-|-|
|
||||||
|
|0x05|0x0A|0x0A|0x0F|0x01|0x01|Нарисовать белый заполненный прямоугольник c координатами x-5, y-10 и размерами по ширине 10, по высоте 15 |0x05 0x0A 0x0A 0x07 0x01 0x01 CxRC|
|
||||||
|
|0x05|0x0A|0x0A|0x0F|0x01|0x00|Нарисовать белый не заполненный прямоугольник c координатами x-5, y-10 и размерами по ширине 10, по высоте 15 |0x05 0x0A 0x0A 0x07 0x01 0x00 CxRC|
|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|
## Нарисовать символ по координатам
|
||||||
|
|
||||||
|
**Команда:**
|
||||||
|
|
||||||
|
0x09
|
||||||
|
|
||||||
|
**Параметры и данные:**
|
||||||
|
|X|Y|Charlndex|Color|
|
||||||
|
|-|-|-|-|
|
||||||
|
|0x00,0x01, … ,0x7F|0x00,0x01, … ,0x3F|0x00,0x01, … ,0x16| 0x00 \| 0x01|
|
||||||
|
|
||||||
|
**Пример:**
|
||||||
|
|X|Y|Charlndex|Color|Описание|Полная команда|
|
||||||
|
|-|-|-|-|-|-|
|
||||||
|
|0x05|0x0A|0x09|0x01|Нарисовать "0" белого цвета c координатами верхнего левого угла символа x-5, y-10|0x09 0x05 0x0A 0x09 0x01 CxRC|
|
||||||
|
|
||||||
|
***
|
159
slave/SPISlave.c
Normal file
159
slave/SPISlave.c
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
#include <avr/io.h>
|
||||||
|
#include "SPISlave.h"
|
||||||
|
#include "head_oled_i2c.h"
|
||||||
|
|
||||||
|
static int index = 0;
|
||||||
|
static int arIndex = 0;
|
||||||
|
static char data[255];
|
||||||
|
|
||||||
|
void SPI_SlaveInit(void)
|
||||||
|
{
|
||||||
|
DDR_SPI = (1 << DD_MISO);
|
||||||
|
SPCR = (1 << SPE) | (1 << SPIE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetCommand(char *data2, int length){
|
||||||
|
char command = data2[0];
|
||||||
|
// Отрезать 1 элемент от оставшихся
|
||||||
|
switch (command){
|
||||||
|
case 1:
|
||||||
|
AllClearCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
SetPageCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
AddSymbolCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
DelSymbolCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
DrawPixelCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
DrawLineCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
DrawCircleCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
DrawRectangleCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
|
DrawCharCommand(&data2[1], length-1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 1
|
||||||
|
void AllClearCommand(char *symbols, int lenght){
|
||||||
|
int param = symbols[0];
|
||||||
|
if (param == 0){
|
||||||
|
Fill(0);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Fill(255);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
ClearPages();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 2
|
||||||
|
void SetPageCommand(char *symbols, int lenght){
|
||||||
|
SetPage(symbols[0]);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 3
|
||||||
|
void AddSymbolCommand(char *symbols, int lenght) {
|
||||||
|
for (int i = 0; i < lenght - 1; i++) {
|
||||||
|
AddSymbol(symbols[i]);
|
||||||
|
}
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 4
|
||||||
|
void DelSymbolCommand(char *symbols, int lenght) {
|
||||||
|
for (int i = 0; i < symbols[0]; i++) {
|
||||||
|
DelSymbol();
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 5
|
||||||
|
void DrawPixelCommand(char *symbols, int lenght){
|
||||||
|
int x = symbols[0];
|
||||||
|
int y = symbols[1];
|
||||||
|
int color = symbols[2];
|
||||||
|
|
||||||
|
DrawPixel(x, y, color);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 6
|
||||||
|
void DrawLineCommand(char *symbols, int lenght){
|
||||||
|
int x = symbols[0];
|
||||||
|
int y = symbols[1];
|
||||||
|
int x1 = symbols[2];
|
||||||
|
int y1 = symbols[3];
|
||||||
|
int color = symbols[4];
|
||||||
|
|
||||||
|
DrawLine(x, y, x1, y1, color);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 7
|
||||||
|
void DrawCircleCommand(char *symbols, int lenght){
|
||||||
|
int x = symbols[0];
|
||||||
|
int y = symbols[1];
|
||||||
|
int r = symbols[2];
|
||||||
|
// white on black color=1, fill=0
|
||||||
|
int color = symbols[3];
|
||||||
|
int fill = symbols[4];
|
||||||
|
|
||||||
|
DrawCircle(x, y, r, color, fill);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 8
|
||||||
|
void DrawRectangleCommand(char *symbols, int lenght){
|
||||||
|
int x = symbols[0];
|
||||||
|
int y = symbols[1];
|
||||||
|
int width = symbols[2];
|
||||||
|
int height = symbols[3];
|
||||||
|
// white on black color=1, fill=0
|
||||||
|
int color = symbols[4];
|
||||||
|
int fill = symbols[5];
|
||||||
|
DrawRect(x, y, width, height, color, fill);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// command 9
|
||||||
|
void DrawCharCommand(char *symbols, int lenght){
|
||||||
|
int x = symbols[0];
|
||||||
|
int y = symbols[1];
|
||||||
|
int charIndex = symbols[2];
|
||||||
|
int fill = symbols[3];
|
||||||
|
// white on black color=1, fill=0
|
||||||
|
|
||||||
|
DrawChar(x, y, charIndex, fill);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
char crc8(char *data, int len) {
|
||||||
|
char crc = 0x00;
|
||||||
|
while (len--) {
|
||||||
|
crc ^= *data++;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
if (crc & 0x80) {
|
||||||
|
crc = (crc << 1) ^ 0x07;
|
||||||
|
} else {
|
||||||
|
crc <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
35
slave/SPISlave.h
Normal file
35
slave/SPISlave.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef SPISlave_H
|
||||||
|
#define SPISlave_H
|
||||||
|
|
||||||
|
#define DDR_SPI DDRB
|
||||||
|
#define DD_MOSI PB3
|
||||||
|
#define DD_MISO PB4
|
||||||
|
#define DD_SCK PB5
|
||||||
|
#define DD_SS PB2
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void SPI_SlaveInit(void);
|
||||||
|
|
||||||
|
void SetCommand(char *data2, int length);
|
||||||
|
|
||||||
|
void AllClearCommand(char *symbols, int lenght);
|
||||||
|
void SetPageCommand(char *symbols, int lenght);
|
||||||
|
void AddSymbolCommand(char *symbols, int lenght);
|
||||||
|
void DelSymbolCommand(char *symbols, int lenght);
|
||||||
|
void DrawPixelCommand(char *symbols, int lenght);
|
||||||
|
void DrawLineCommand(char *symbols, int lenght);
|
||||||
|
void DrawCircleCommand(char *symbols, int lenght);
|
||||||
|
void DrawRectangleCommand(char *symbols, int lenght);
|
||||||
|
void DrawCharCommand(char *symbols, int lenght);
|
||||||
|
|
||||||
|
char crc8(char *data, int len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
85
slave/head_oled_i2c.h
Normal file
85
slave/head_oled_i2c.h
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#ifndef head_oled_i2c
|
||||||
|
#define head_oled_i2c
|
||||||
|
|
||||||
|
#define OLED_HEIGHT_64 0x12
|
||||||
|
#define OLED_64 0x3F
|
||||||
|
|
||||||
|
#define OLED_DISPLAY_OFF 0xAE
|
||||||
|
#define OLED_DISPLAY_ON 0xAF
|
||||||
|
|
||||||
|
#define OLED_COMMAND_MODE 0x00
|
||||||
|
#define OLED_ONE_COMMAND_MODE 0x80
|
||||||
|
#define OLED_DATA_MODE 0x40
|
||||||
|
|
||||||
|
#define OLED_ADDRESSING_MODE 0x20
|
||||||
|
#define OLED_VERTICAL 0x01
|
||||||
|
|
||||||
|
#define OLED_NORMAL_V 0xC8
|
||||||
|
#define OLED_NORMAL_H 0xA1
|
||||||
|
|
||||||
|
#define OLED_CONTRAST 0x81
|
||||||
|
#define OLED_SETCOMPINS 0xDA
|
||||||
|
#define OLED_SETVCOMDETECT 0xDB
|
||||||
|
#define OLED_CLOCKDIV 0xD5
|
||||||
|
#define OLED_SETMULTIPLEX 0xA8
|
||||||
|
#define OLED_COLUMNADDR 0x21
|
||||||
|
#define OLED_PAGEADDR 0x22
|
||||||
|
#define OLED_CHARGEPUMP 0x8D
|
||||||
|
|
||||||
|
#define OLED_NORMALDISPLAY 0xA6
|
||||||
|
|
||||||
|
#define OLED_BUFSIZE (128*64/8)
|
||||||
|
|
||||||
|
#define OLED_MAX_X 127
|
||||||
|
#define OLED_MAX_Y 63
|
||||||
|
#define OLED_MAX_ROW 7
|
||||||
|
|
||||||
|
#define OLED_ADDR 0x3C
|
||||||
|
#define OLED_I2C_FREQ 100000UL
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void i2c_begin(uint8_t address);
|
||||||
|
void i2c_endTransaction();
|
||||||
|
void i2c_beginTransmission(uint8_t address);
|
||||||
|
void i2c_write(uint8_t data);
|
||||||
|
|
||||||
|
void endTransm();
|
||||||
|
void sendByteRaw(uint8_t data);
|
||||||
|
void startTransm();
|
||||||
|
void beginData();
|
||||||
|
void sendByte(uint8_t data);
|
||||||
|
|
||||||
|
void sendCommand(uint8_t cmd1);
|
||||||
|
void sendCommandData(uint8_t cmd1, uint8_t cmd2);
|
||||||
|
uint8_t constrainValue(uint8_t value, uint8_t min, uint8_t max);
|
||||||
|
void setWindow(int x0, int y0, int x1, int y1);
|
||||||
|
|
||||||
|
void beginCommand();
|
||||||
|
void beginOneCommand();
|
||||||
|
|
||||||
|
void initialization();
|
||||||
|
|
||||||
|
void setBit(uint8_t *value, uint8_t bitIndex, uint8_t bitValue);
|
||||||
|
void DrawPixel(uint8_t x, uint8_t y, uint8_t fill);
|
||||||
|
void DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color);
|
||||||
|
void DrawRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t fill);
|
||||||
|
void DrawCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t fill);
|
||||||
|
void Fill(uint8_t fill);
|
||||||
|
void update();
|
||||||
|
|
||||||
|
void DrawChar(uint8_t x, uint8_t y, uint8_t charIndex, uint8_t fill);
|
||||||
|
void ClearPages();
|
||||||
|
void AddSymbol(uint8_t symbol);
|
||||||
|
void DelSymbol();
|
||||||
|
void SetPage(uint8_t p);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
318
slave/oled_i2c.c
Normal file
318
slave/oled_i2c.c
Normal file
@ -0,0 +1,318 @@
|
|||||||
|
#include "stdint.h"
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include "head_oled_i2c.h"
|
||||||
|
|
||||||
|
uint8_t _oled_buffer[OLED_BUFSIZE];
|
||||||
|
uint8_t _writes = 0;
|
||||||
|
|
||||||
|
void i2c_begin(uint8_t address) {
|
||||||
|
TWBR = ((F_CPU / OLED_I2C_FREQ) - 16) / 2;
|
||||||
|
TWAR = (address << 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_endTransaction() {
|
||||||
|
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_beginTransmission(uint8_t address) {
|
||||||
|
TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN);
|
||||||
|
while (!(TWCR & (1 << TWINT)));
|
||||||
|
|
||||||
|
TWDR = (address << 1);
|
||||||
|
TWCR = (1 << TWINT) | (1 << TWEN);
|
||||||
|
while (!(TWCR & (1 << TWINT)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_write(uint8_t data) {
|
||||||
|
TWDR = data; // Запись данных
|
||||||
|
TWCR = (1 << TWINT) | (1 << TWEN);
|
||||||
|
while (!(TWCR & (1 << TWINT)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void endTransm() {
|
||||||
|
i2c_endTransaction();
|
||||||
|
_writes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendByteRaw(uint8_t data) {
|
||||||
|
i2c_write(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void startTransm() {
|
||||||
|
i2c_beginTransmission(OLED_ADDR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginCommand() {
|
||||||
|
startTransm();
|
||||||
|
sendByteRaw(OLED_COMMAND_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginData() {
|
||||||
|
startTransm();
|
||||||
|
sendByteRaw(OLED_DATA_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendByte(uint8_t data) {
|
||||||
|
sendByteRaw(data);
|
||||||
|
_writes++;
|
||||||
|
if (_writes >= 16) {
|
||||||
|
endTransm();
|
||||||
|
beginData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void beginOneCommand() {
|
||||||
|
startTransm();
|
||||||
|
sendByteRaw(OLED_ONE_COMMAND_MODE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendCommand(uint8_t cmd1) {
|
||||||
|
beginOneCommand();
|
||||||
|
sendByteRaw(cmd1);
|
||||||
|
endTransm();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendCommandData(uint8_t cmd1, uint8_t cmd2) {
|
||||||
|
beginCommand();
|
||||||
|
sendByteRaw(cmd1);
|
||||||
|
sendByteRaw(cmd2);
|
||||||
|
endTransm();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t constrainValue(uint8_t value, uint8_t min, uint8_t max) {
|
||||||
|
if (value < min) {
|
||||||
|
return min;
|
||||||
|
} else if (value > max) {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setWindow(int x0, int y0, int x1, int y1) {
|
||||||
|
beginCommand();
|
||||||
|
sendByteRaw(OLED_COLUMNADDR);
|
||||||
|
sendByteRaw(constrainValue(x0, 0, OLED_MAX_X));
|
||||||
|
sendByteRaw(constrainValue(x1, 0, OLED_MAX_X));
|
||||||
|
sendByteRaw(OLED_PAGEADDR);
|
||||||
|
sendByteRaw(constrainValue(y0, 0, OLED_MAX_ROW));
|
||||||
|
sendByteRaw(constrainValue(y1, 0, OLED_MAX_ROW));
|
||||||
|
endTransm();
|
||||||
|
}
|
||||||
|
|
||||||
|
void initialization() {
|
||||||
|
i2c_begin(OLED_ADDR);
|
||||||
|
|
||||||
|
beginCommand();
|
||||||
|
sendByte(OLED_DISPLAY_OFF);
|
||||||
|
sendByte(OLED_CLOCKDIV);
|
||||||
|
sendByte(0x80);
|
||||||
|
sendByte(OLED_CHARGEPUMP);
|
||||||
|
sendByte(0x14);
|
||||||
|
sendByte(OLED_ADDRESSING_MODE);
|
||||||
|
sendByte(OLED_VERTICAL);
|
||||||
|
sendByte(OLED_NORMAL_H);
|
||||||
|
sendByte(OLED_NORMAL_V);
|
||||||
|
sendByte(OLED_CONTRAST);
|
||||||
|
sendByte(0x7F);
|
||||||
|
sendByte(OLED_SETVCOMDETECT);
|
||||||
|
sendByte(0x40);
|
||||||
|
sendByte(OLED_NORMALDISPLAY);
|
||||||
|
sendByte(OLED_DISPLAY_ON);
|
||||||
|
endTransm();
|
||||||
|
|
||||||
|
beginCommand();
|
||||||
|
sendByte(OLED_SETCOMPINS);
|
||||||
|
sendByte(OLED_HEIGHT_64);
|
||||||
|
sendByte(OLED_SETMULTIPLEX);
|
||||||
|
sendByte(OLED_64);
|
||||||
|
endTransm();
|
||||||
|
|
||||||
|
setWindow(0, 0, OLED_MAX_X, OLED_MAX_ROW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBit(uint8_t *value, uint8_t bitIndex, uint8_t bitValue) {
|
||||||
|
if (bitValue != 0) {
|
||||||
|
*value |= (1 << bitIndex);
|
||||||
|
} else {
|
||||||
|
*value &= ~(1 << bitIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawPixel(uint8_t x, uint8_t y, uint8_t fill) {
|
||||||
|
if (x < 0 || x > OLED_MAX_X || y < 0 || y > OLED_MAX_Y) return;
|
||||||
|
uint16_t _bufIndex = ((y) >> 3) + ((x) << (3));
|
||||||
|
setBit(&_oled_buffer[_bufIndex], y & 0b111, fill);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint8_t color) {
|
||||||
|
uint8_t dx = abs(x2 - x1);
|
||||||
|
uint8_t dy = abs(y2 - y1);
|
||||||
|
uint8_t sx = x1 < x2 ? 1 : -1;
|
||||||
|
uint8_t sy = y1 < y2 ? 1 : -1;
|
||||||
|
uint8_t err = dx - dy;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
DrawPixel(x1, y1, color);
|
||||||
|
|
||||||
|
if (x1 == x2 && y1 == y2) break;
|
||||||
|
|
||||||
|
uint8_t e2 = 2 * err;
|
||||||
|
|
||||||
|
if (e2 > -dy) {
|
||||||
|
err -= dy;
|
||||||
|
x1 += sx;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e2 < dx) {
|
||||||
|
err += dx;
|
||||||
|
y1 += sy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawRect(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color, uint8_t fill) {
|
||||||
|
if (fill) {
|
||||||
|
for (uint8_t i = y; i < y + height; i++) {
|
||||||
|
DrawLine(x, i, x + width - 1, i, color);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (uint8_t i = x; i < x + width; i++) {
|
||||||
|
DrawPixel(i, y, color);
|
||||||
|
DrawPixel(i, y + height - 1, color);
|
||||||
|
}
|
||||||
|
for (uint8_t i = y; i < y + height; i++) {
|
||||||
|
DrawPixel(x, i, color);
|
||||||
|
DrawPixel(x + width - 1, i, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void DrawCircle(uint8_t x0, uint8_t y0, uint8_t radius, uint8_t color, uint8_t fill) {
|
||||||
|
int8_t x = radius;
|
||||||
|
int8_t y = 0;
|
||||||
|
int8_t err = 0;
|
||||||
|
|
||||||
|
while (x >= y) {
|
||||||
|
if (fill) {
|
||||||
|
for (int8_t i = x0 - x; i <= x0 + x; i++) {
|
||||||
|
DrawPixel(i, y0 + y, color);
|
||||||
|
DrawPixel(i, y0 - y, color);
|
||||||
|
}
|
||||||
|
for (int8_t i = x0 - y; i <= x0 + y; i++) {
|
||||||
|
DrawPixel(i, y0 + x, color);
|
||||||
|
DrawPixel(i, y0 - x, color);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
DrawPixel(x0 + x, y0 + y, color);
|
||||||
|
DrawPixel(x0 - x, y0 + y, color);
|
||||||
|
DrawPixel(x0 + x, y0 - y, color);
|
||||||
|
DrawPixel(x0 - x, y0 - y, color);
|
||||||
|
DrawPixel(x0 + y, y0 + x, color);
|
||||||
|
DrawPixel(x0 - y, y0 + x, color);
|
||||||
|
DrawPixel(x0 + y, y0 - x, color);
|
||||||
|
DrawPixel(x0 - y, y0 - x, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
y++;
|
||||||
|
err += 1 + 2 * y;
|
||||||
|
if (2 * (err - x) + 1 > 0) {
|
||||||
|
x--;
|
||||||
|
err += 1 - 2 * x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Заполнить дисплей
|
||||||
|
void Fill(uint8_t fill) {
|
||||||
|
memset(_oled_buffer, fill, OLED_BUFSIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обновить дисплей
|
||||||
|
void update() {
|
||||||
|
setWindow(0, 0, OLED_MAX_X, OLED_MAX_ROW);
|
||||||
|
beginData();
|
||||||
|
for (int i = 0; i < OLED_BUFSIZE; i++) sendByte(_oled_buffer[i]);
|
||||||
|
endTransm();
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t _charMap[][5] = {
|
||||||
|
{0x00, 0x00, 0x00, 0x00, 0x00}, // 0x00 32
|
||||||
|
{0x00, 0x1c, 0x22, 0x41, 0x00}, // ( 0x01 33
|
||||||
|
{0x00, 0x41, 0x22, 0x1c, 0x00}, // ) 0x02 34
|
||||||
|
{0x14, 0x08, 0x3e, 0x08, 0x14}, // * 0x03 35
|
||||||
|
{0x08, 0x08, 0x3e, 0x08, 0x08}, // + 0x04 36
|
||||||
|
{0x00, 0x50, 0x30, 0x00, 0x00}, // , 0x05 37
|
||||||
|
{0x08, 0x08, 0x08, 0x08, 0x08}, // - 0x06 38
|
||||||
|
{0x00, 0x60, 0x60, 0x00, 0x00}, // . 0x07 39
|
||||||
|
{0x20, 0x10, 0x08, 0x04, 0x02}, // / 0x08 40
|
||||||
|
{0x3e, 0x51, 0x49, 0x45, 0x3e}, // 0 0x09 41
|
||||||
|
{0x00, 0x42, 0x7f, 0x40, 0x00}, // 1 0x0a 42
|
||||||
|
{0x42, 0x61, 0x51, 0x49, 0x46}, // 2 0x0b 43
|
||||||
|
{0x21, 0x41, 0x45, 0x4b, 0x31}, // 3 0x0c 44
|
||||||
|
{0x18, 0x14, 0x12, 0x7f, 0x10}, // 4 0x0d 45
|
||||||
|
{0x27, 0x45, 0x45, 0x45, 0x39}, // 5 0x0e 46
|
||||||
|
{0x3c, 0x4a, 0x49, 0x49, 0x30}, // 6 0x0f 47
|
||||||
|
{0x01, 0x71, 0x09, 0x05, 0x03}, // 7 0x10 48
|
||||||
|
{0x36, 0x49, 0x49, 0x49, 0x36}, // 8 0x11 49
|
||||||
|
{0x06, 0x49, 0x49, 0x29, 0x1e}, // 9 0x12 50
|
||||||
|
{0x00, 0x36, 0x36, 0x00, 0x00}, // : 0x13 51
|
||||||
|
{0x08, 0x14, 0x22, 0x41, 0x00}, // < 0x14 52
|
||||||
|
{0x14, 0x14, 0x14, 0x14, 0x14}, // = 0x15 53
|
||||||
|
{0x00, 0x41, 0x22, 0x14, 0x08}, // > 0x16 54
|
||||||
|
};
|
||||||
|
|
||||||
|
void DrawChar(uint8_t x, uint8_t y, uint8_t charIndex, uint8_t fill) {
|
||||||
|
// Проверяем, что индекс символа находится в допустимых пределах
|
||||||
|
if (charIndex >= sizeof(_charMap) / sizeof(_charMap[0])) {
|
||||||
|
return; // Символ не найден
|
||||||
|
}
|
||||||
|
|
||||||
|
// Рисуем символ пиксель за пикселем
|
||||||
|
for (uint8_t col = 0; col < 5; col++) {
|
||||||
|
uint8_t columnData = _charMap[charIndex][col];
|
||||||
|
|
||||||
|
for (uint8_t row = 0; row < 8; row++) {
|
||||||
|
if (columnData & (1 << row)) {
|
||||||
|
DrawPixel(x + col, y + row, fill);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t page = 0;
|
||||||
|
uint8_t amountByteInPage[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
|
|
||||||
|
void SetPage(uint8_t p){
|
||||||
|
page = p;
|
||||||
|
if (p < 0) page = 0;
|
||||||
|
if (p > 8) page = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearPages(){
|
||||||
|
for (uint8_t row = 0; row < 8; row++) {
|
||||||
|
amountByteInPage[row] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddSymbol(uint8_t symbol){
|
||||||
|
if (amountByteInPage[page] + 5 < 128){
|
||||||
|
DrawChar(amountByteInPage[page],page*8,symbol,1);
|
||||||
|
amountByteInPage[page] += 6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the last symbol from the display buffer
|
||||||
|
void DelSymbol(){
|
||||||
|
if (amountByteInPage[page] - 6 <= 0){
|
||||||
|
amountByteInPage[page] = 0;
|
||||||
|
DrawRect(amountByteInPage[page],page*8,127,8,0,1);
|
||||||
|
}else{
|
||||||
|
amountByteInPage[page] -= 6;
|
||||||
|
DrawRect(amountByteInPage[page],page*8,6,8,0,1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
42
slave/slave.ino
Normal file
42
slave/slave.ino
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#include "SPISlave.h"
|
||||||
|
#include "head_oled_i2c.h"
|
||||||
|
|
||||||
|
static int index = 0;
|
||||||
|
static int arIndex = 0;
|
||||||
|
static char data[64];
|
||||||
|
|
||||||
|
ISR(SPI_STC_vect)
|
||||||
|
{
|
||||||
|
char received = SPDR;
|
||||||
|
data[index] = received;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
SPI_SlaveInit();
|
||||||
|
initialization();
|
||||||
|
|
||||||
|
Fill(0);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if(PINB & (1 << 2)){
|
||||||
|
if(index > 0){
|
||||||
|
char sum = 0;
|
||||||
|
sum = crc8(data, index-1);
|
||||||
|
char last_1 = data[index - 1];
|
||||||
|
|
||||||
|
if (last_1 == sum){
|
||||||
|
SetCommand(data, index);
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user