I’m trying to use a global array to store data that I know won’t be greater than 255 bytes. But when I try to transmit my data using the array, nothing seems to transmit. What am I doing wrong?
char responseFrame[255];
int main {
...
while(1){
getData();
}
};
void getData(void) {
int responseLen = USART1_RX();
// put data in the response frame
for (int i = 0; i < responseLen; i++){
recv_data = USART1_RX();
responseFrame[i]=recv_data;
//USART0_TX(responseFrame[i]);
}
LogOutput(responseFrame, responseLen);
}
void LogOutput(char *msg, int size) {
int i;
for (i = 0; i < size; i++) {
USART0_TX(msg[i]);
}
}
However, when I comment the my logging function “LogOutput” and use a straight transmit using the line “USART0_TX(responseFrame[i])”, it appropriately transmit the information.
Here is my USART0_TX function:
void USART0_TX(uint8_t myData) {
// Wait if a byte is being transmitted
while( !(UCSR0A & (1<<UDRE0)) );
// Transmit data
UDR0 = myData;
};
Are you sure your LogOutput function is being passed valid data?
This should work
Another thought:
Are you running the compiler with any optimizations? Try turning them off to see if the problem goes away.
Also, you may want to consider marking the global volatile.