Created
October 8, 2012 15:05
-
-
Save pepyakin/3853003 to your computer and use it in GitHub Desktop.
Basic example msp430-uart for reading 16 bytes and then sending it back at once.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* example.c | |
*/ | |
#include <msp430g2553.h> | |
#include <uart.h> | |
#define ARRAY_SIZE 16 | |
/** | |
* Read 16 bytes and then send it back. Forever loop. | |
*/ | |
void test_arrays() { | |
char buffer[ARRAY_SIZE]; | |
unsigned char next = 0; | |
while (1) { | |
// Get single character from UART stream. If | |
// there is no character - it will wait one and then return it. | |
unsigned char ch = uart_getc(); | |
buffer[next++] = ch; | |
if (next == ARRAY_SIZE) { | |
// 16 bytes received. Send data chunk | |
// back to the sender and clear 'next' indexer. | |
uart_putn(buffer, ARRAY_SIZE); | |
next = 0; | |
} | |
} | |
} | |
void main(void) { | |
// Holding down the watchdog. | |
WDTCTL = WDTPW | WDTHOLD; | |
// Before using uart_ functions, you must | |
// initialize uart module. | |
uart_init(); | |
test_arrays(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment