by atomowka » Sun Jan 13, 2013 7:55 pm
by atomowka
Sun Jan 13, 2013 7:55 pm
Hi!
I have wrote some simple code in Studio AVR to connect ZIG-100 and CM-5. Unfortunately it is not working correctly. The robot recieves my message from PC and it sends back something else like when I sends 1 I got back 241.
I am checking the transmission by using Docklight.
Thanks in advance!
My code underneath:
#include <avr>
#include <avr>
#include <stdio>
#include <util>
//#define F_CPU 8000000UL // zegar w Hz
#define F_CPU 16000000UL // 16MHz
//#define FOSC 1843200
#define RS_BAUD 38400
#define RS_UBRR F_CPU / 16 / RS_BAUD - 1
void uart_init(uint16_t ubrr)
{
PORTD &= ~0x80; //PORT_LINK_PLUGIN = 0; // no pull up
PORTD &= ~0x20; //PORT_ENABLE_RXD_LINK_PC = 0;
PORTD |= 0x40; //PORT_ENABLE_RXD_LINK_ZIGBEE = 1;
UCSR1A = 0b01000010;//
UCSR1B = 0b10011000;//
UCSR1C = 0b00000110;//
UBRR1H = (unsigned char)((RS_UBRR & 0xFF00) >> 8);
UBRR1L = (unsigned char)(RS_UBRR & 0x00FF);
// initialize
UDR1 = 0xFF;
}
void uart_putc(uint8_t data)
{
// Oczekiwanie na zakończenie nadawania
while (!(UCSR1A & (1 << UDRE1)));
// Wysłanie danych
UDR1 = data;
}
uint8_t uart_ischar()
{
// Czy w buforze są dane?
return (UCSR1A & (1 << RXC1));
}
uint8_t uart_getc()
{
// Czy w buforze są dane?
while(!uart_ischar());
// Dane z bufora
return UDR1;
}
int main(void)
{
uint8_t c;
uart_init(RS_UBRR);
while(1)
{
c = uart_getc();
_delay_ms(500);
uart_putc(c);
}
}
Hi!
I have wrote some simple code in Studio AVR to connect ZIG-100 and CM-5. Unfortunately it is not working correctly. The robot recieves my message from PC and it sends back something else like when I sends 1 I got back 241.
I am checking the transmission by using Docklight.
Thanks in advance!
My code underneath:
#include <avr>
#include <avr>
#include <stdio>
#include <util>
//#define F_CPU 8000000UL // zegar w Hz
#define F_CPU 16000000UL // 16MHz
//#define FOSC 1843200
#define RS_BAUD 38400
#define RS_UBRR F_CPU / 16 / RS_BAUD - 1
void uart_init(uint16_t ubrr)
{
PORTD &= ~0x80; //PORT_LINK_PLUGIN = 0; // no pull up
PORTD &= ~0x20; //PORT_ENABLE_RXD_LINK_PC = 0;
PORTD |= 0x40; //PORT_ENABLE_RXD_LINK_ZIGBEE = 1;
UCSR1A = 0b01000010;//
UCSR1B = 0b10011000;//
UCSR1C = 0b00000110;//
UBRR1H = (unsigned char)((RS_UBRR & 0xFF00) >> 8);
UBRR1L = (unsigned char)(RS_UBRR & 0x00FF);
// initialize
UDR1 = 0xFF;
}
void uart_putc(uint8_t data)
{
// Oczekiwanie na zakończenie nadawania
while (!(UCSR1A & (1 << UDRE1)));
// Wysłanie danych
UDR1 = data;
}
uint8_t uart_ischar()
{
// Czy w buforze są dane?
return (UCSR1A & (1 << RXC1));
}
uint8_t uart_getc()
{
// Czy w buforze są dane?
while(!uart_ischar());
// Dane z bufora
return UDR1;
}
int main(void)
{
uint8_t c;
uart_init(RS_UBRR);
while(1)
{
c = uart_getc();
_delay_ms(500);
uart_putc(c);
}
}