void main (void)
{
	WDTCTL = WDTPW | WDTHOLD;		// Stop watchdog timer

    // Set 16MHz clock
	BCSCTL1 = CALBC1_16MHZ;
	DCOCTL = CALDCO_16MHZ;
	// Startup Delay
	_delay_cycles(2000);

	// Initialize serial port
	SERIAL_init();
	// Enable interrupt
	_EINT();
	rxEchoPos = 0;

	// Set the servo port to digital output
	P2DIR |= BIT2;

 	int deg; // servo rotation degree

 	// Main loop
 	while(1)
 	{
 		// load the target degree from the serial port
 		deg = checkSerial();
 		// if there is a new value
 		if(deg > -1)
 		{
 			// Move the servo
 			moveServo(deg);
 		}
 		__delay_cycles(1000);
 	}
}
Example #2
0
int main(void)
{
	SystemInit();

	//init
	LOG_init();
	SERIAL_init();

	//SERIAL_selftest();
	while (1)
	{
		SERIAL_send("hello from STM32");
		u8* buffer = SERIAL_receive();
		LOG(buffer);
		SERIAL_freebuffer(buffer);
	}
}