Colorduino Library и Arduino Mega не хотят дружить...
- Войдите на сайт для отправки комментариев
Здравствуйте.
Возникла проблема, с которой бьюсь уже третий день. С Arduino только знакомлюсь.
И так суть проблемы купил:
Arduino Mega (ATMega 1280)
Colors Shield V1.1
Скачал библиотеку:
Colorduino Library V1.2
Но библиотека как и сам шилд сделанны для Arduini Uni :(
Сказали что распиновка у микроконтроллеров разная, нужно поправить в библиотеке распиновку.
Colorduino.h
В оригинале:
#define RST_BIT 0x04
#define LAT_BIT 0x02
#define SLB_BIT 0x01
#define SCL_BIT 0x40
#define SDA_BIT 0x80
#define RST PORTC
#define LAT PORTC
#define SLB PORTC
#define SDA PORTD
#define SCL PORTD
#define open_line0 {PORTB=0x01;}
#define open_line1 {PORTB=0x02;}
#define open_line2 {PORTB=0x04;}
#define open_line3 {PORTB=0x08;}
#define open_line4 {PORTB=0x10;}
#define open_line5 {PORTB=0x20;}
#define open_line6 {PORTD=0x08;}
#define open_line7 {PORTD=0x10;}
#define close_all_lines {PORTD=0x00;PORTB=0x00;}
void _IO_Init()
{
DDRD = 0xff; // set all pins direction of PortD
DDRC = 0xff; // set all pins direction of PortC
DDRB = 0xff; // set all pins direction of PortB
PORTD = 0x00; // set all pins output is low of PortD
PORTC = 0x00; // set all pins output is low of PortC
PORTB = 0x00; // set all pins output is low of PortB
}
Я шилд повесил на провода и воткнул в другие выходы (чтобы для указания линии использовался один регистр), после правки код стал таким:
/*****************************
define the IO
*****************************/
#define SLB PORTF
#define SLB_BIT 0x01
#define LAT PORTF
#define LAT_BIT 0x02
#define RST PORTF
#define RST_BIT 0x04
#define SDA PORTH
#define SDA_BIT 0x10
#define SCL PORTH
#define SCL_BIT 0x08
#define open_line0 {PORTB=0x01;}
#define open_line1 {PORTB=0x02;}
#define open_line2 {PORTB=0x04;}
#define open_line3 {PORTB=0x08;}
#define open_line4 {PORTB=0x10;}
#define open_line5 {PORTB=0x20;}
#define open_line6 {PORTB=0x40;}
#define open_line7 {PORTB=0x80;}
#define close_all_lines {PORTB=0x00;}
void _IO_Init()
{
DDRF = 0xFF;
PORTF = 0x00;
DDRH = DDRH | B00011000;
PORTH = PORTH | B00000000;
DDRB = 0xFF; // set all pins direction of PortB
PORTB = 0x00; // set all pins output is low of PortB
}
Вроде с выходами разобрался, но шилд все равно не хочет работать. Пробую запустить демо код из поставки с библиотекой.
Мне кажется что проблема со таймером, вот кусочек кода инициализации:
void _TC2_Init()
{
// Arduino runs at 16 Mhz...
// Timer Settings, for the Timer Control Register etc. , thank you internets. ATmega168 !
// Timer2 (8bit) Settings:
// prescaler (frequency divider) values: CS22 CS21 CS20
// 0 0 0 stopped
// 0 0 1 /1
// 0 1 0 /8
// 0 1 1 /32
// 1 0 0 /64
// 1 0 1 /128
// 1 1 0 /256
// 1 1 1 /1024
// TCNT2 increments every = 16MHz / prescaler
// set prescaler to 128 -> TCNT2 freq = 125KHz
TCCR2B |= ((1<<CS22)|(1<<CS20));
TCCR2B &= ~((1<<CS21));
TCCR2A &= ~((1<<WGM21) | (1<<WGM20)); // Use normal mode
ASSR |= (1<<AS2); // Use internal clock - external clock not used in Arduino
TIMSK2 |= (1<<TOIE2) | (0<<OCIE2B); //Timer2 Overflow Interrupt Enable
TCNT2 = 0xff;
sei();
}
Как его поправить для моей версии контроллера, я даже предположить не могу, даташит листаю а понять его не могу((((
Помогите новичку советом или кусочком кода...
Я его все таки победил, постю ответ на ребус, т.к. в интернете его нет.
Подключение у меня не стандартное а выносное, поэтому кому надо будет для установки на плату придется додумывать курить даташит на чип микроконтроллера. Использовать придется другой таймер и адреса портов поменяются.
Подключение, я подлючал проводами так что:
Правки в коде:
/** * * define the IO * */ #define RST_BIT 0x04 #define LAT_BIT 0x02 #define SLB_BIT 0x01 #define SCL_BIT 0x40 #define SDA_BIT 0x20 #define RST PORTF #define LAT PORTF #define SLB PORTF #define SDA PORTH #define SCL PORTH #define open_line0 { PORTB=0x01; } #define open_line1 { PORTB=0x02; } #define open_line2 { PORTB=0x04; } #define open_line3 { PORTB=0x08; } #define open_line4 { PORTB=0x10; } #define open_line5 { PORTB=0x20; } #define open_line6 { PORTB=0x40; } #define open_line7 { PORTB=0x80; } #define close_all_lines { PORTB=0x00; } void _IO_Init() { DDRB = 0xff; // set all pins direction of PortD PORTB = 0x00; // set all pins output is low of PortD DDRF = DDRF | B00000111; // set all pins direction of PortC DDRH = DDRH | B01100000; PORTH = PORTH | B00000000; } void _TC2_Init() { // set prescaler to 128 -> TCNT2 freq = 125KHz TCCR2A |= ((1<<CS22)|(1<<CS20)); TCCR2A &= ~((1<<CS21)); TCCR2B &= ~((1<<WGM21) | (1<<WGM20)); // Use normal mode ASSR |= (0<<AS2); // Use internal clock - external clock not used in Arduino TIMSK2 |= (1<<TOIE2) | (0<<OCIE2A); //Timer2 Overflow Interrupt Enable TCNT2 = 0xff; sei(); }