after getting my debug problem solved and things back up and working i have had time now to start debugging my uart Tx line. my code posted below is sending a a 4byte static(currently) value with 3 bits as a sync, address and crc framing the packet. eg [sync][address][data][]data][data][data][crc]
when executing the code real time only the first two bytes are sent when tx_packet is called. if the first two bytes are commented out then it will be the following two bytes that will send. When stepping through the code in debug mode all 7 bytes will send when executed step by step.
Below is my code. Any help is as usual much appreciated!
#include#include "avr/interrupt.h" #include "stdint.h" #include "util/delay.h" #define F_CPU 8000000UL //define receive parameters #define SYNC 0XAA // synchro signal #define RADDR 0x44 volatile unsigned char torque_h, torque_l, rpm_h, rpm_l; void init_uart() { //set baud rate 9600bps UBRR0 = 51; //enable Tx UCSR0B = 0b00001000; //set frame format 8,n,1 UCSR0C = 0b00001110; return; } void tx_byte(unsigned char sendbyte) { //wait for empty Tx buffer and reset flag if set if(UCSR0A & (1<<TXC0)) { UCSR0A |= (1<<TXC0); } while ((UCSR0A & (1<<UDRE0)) !=0) { // Put data into buffer, sends the data UDR0 = sendbyte; break; } return(0); } void tx_packet(unsigned char address) { unsigned char crc; crc =0; crc = torque_h + torque_l + rpm_h + rpm_l; //send on sync byte to initialize wireless tx_byte(SYNC); //transmit adress tx_byte(address); //send data tx_byte(torque_h); tx_byte(torque_l); tx_byte(rpm_h); tx_byte(rpm_l); return(0); } void init_ADC0() { //ADMUX - ADC MUltiplexer Selection Register ADMUX |= (0<<REFS1) | (1<<REFS0); //AVcc as Vref, with external capacitor at aref pin ADMUX |= (0<<MUX3) | (0<<MUX2) | (0<<MUX1) | (0<<MUX0); //ADC0 single ended iunput //ADCSRA - ADC Control and Status Register A ADCSRA |= (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0); //enable adc, 128 prescale //ADCSRB - ADC Control and Status Register B // used for auto trigger of adc, not needed for this initial test purpose } unsigned int read_ADC0(unsigned char average) {//average 1-63 unsigned int reading; unsigned char count; reading = 0; count = 0; for (count; count <= average; count++) { ADCSRA |= (1<<ADIF); //write 1 to ADICF to clear done flag ADCSRA |= (1<<ADSC); //start conversion while (ADCSRA == (1<<ADIF)); { reading += ADCL | (ADCH<<8); } } return(reading/average); } main() { unsigned char test2, i; //DDRD |= (1<<PD1);// | (1<<PB1); //enable as output as RF Vcc pin //ORTD |= (1<<PB2); // turn on teh RF chip //Initialize ADC0 init_ADC0(); init_uart(); sei(); torque_h = 0xFA; torque_l = 0x13; rpm_h = 0x10; rpm_l = 0xFF; while(1){ // test2 =0xAA; // tx_byte(test2); tx_packet(RADDR); _delay_loop_2(30000); } return; }