CS4101 嵌入式系統概論 Software UART Revisited Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan ( Materials from MSP430.

Slides:



Advertisements
Similar presentations
Lab 1 I/O, timers, interrupts on the eZ430-RF2500 Thomas Watteyne EE290Q – Spring 2010
Advertisements

Serial Communications (Chapter 10)
Review: Interrupts & Timers
Outline MSP430 LaunchPad MSP430 Microcontroller
Interrupts, Low Power Modes and Timer A (Chapters 6 & 8)
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
Chung-Ta King National Tsing Hua University
ECE 447 Fall 2009 Lecture 9: TI MSP430 Interrupts & Low Power Modes.
LAB 6: Serial Communication
CS4101 嵌入式系統概論 Timers and Clocks 金仲達教授 國立清華大學資訊工程學系 Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008.
Chung-Ta King National Tsing Hua University
LAB 7: WDT+ and Low-Power Optimization
Lecture 18: ADC Implementation Lecturers: Professor John Devlin.
1 MSP430F2013: 2KB + 256B Flash Memory 128B RAM. 2 MSP430 MSP ( mixed signal processor) The CPU is small and efficient, with a large number of registers.
MSP430 Mixed Signal Microcontroller – Parte 2 Afonso Ferreira Miguel Source: slau056d – Texas instruments.
CPE 323 Introduction to Embedded Computer Systems: Watchdog Timer, Timer A Instructor: Dr Aleksandar Milenkovic Lecture Notes.
Lecture Set 9 MCS-51 Serial Port.
CS4101 嵌入式系統概論 Analog-to-Digital Converter 金仲達教授 國立清華大學資訊工程學系 ( Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008 )
Lecture 11: TI MSP430 Timers Compare Modes
LAB 8: Program Design Pattern and Software Architecture
Ultra-low Power Motion Detection using the MSP430F2013.
Arch1 LCD Lab Eric Freudenthal. Topics Score Demo LCD Panel Geometry Utilities to draw to the display Drawing characters Buttons Nuisance: multiple versions.
1 Wireless Body Area Network. 2 MSP430F2013: 2KB + 256B Flash Memory 128B RAM.
Network and Systems Laboratory nslab.ee.ntu.edu.tw.
Week 7 Low-Power Modes MSP430 Teaching Materials Hacettepe University Copyright 2009 Texas Instruments All Rights Reserved.
CS4101 嵌入式系統概論 Interrupt 金仲達教授 國立清華大學資訊工程學系 ( Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008 )
1 MSP430F2013: 2KB + 256B Flash Memory 128B RAM. 2 MSP430F2013.
UNIT 2. CPUXV2 20-bit addressing User-definable Boot Strap Loader RAM starts at 0x1C00 Beginning of MAIN flash moves according to RAM Vector table starts.
ECE 382 Lesson 32 Lesson Outline Lab 6 Introduction Pulse Width Modulation Capture / Compare Example Lab 6 Tips Admin Lab#6 “prelab” due BOC lesson 33.
Recall the Container Thermometer
Recall the Container Thermometer
Lab 7 Basic 1: Game of Memory
Introduction Why low power?
Introduction Why low power?
CS4101 嵌入式系統概論 General Purpose IO
Recall the Container Thermometer
ECE 3430 – Intro to Microcomputer Systems
Lecture 8: TI MSP430 Interrupts, ISRs
CS4101 嵌入式系統概論 Serial Communication
EMBEDDED SYSTEMS UNIT 4.
CS4101 嵌入式系統概論 Introduction to LaunchPad
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
Lesson Outline Interrupts Admin Assignment #9 due next lesson
PWM and DC Motor Control
CS4101 Introduction to Embedded Systems Lab 6: Low-Power Optimization
CS4101 嵌入式系統概論 Interrupts Prof. Chung-Ta King
CS4101 Introduction to Embedded Systems Lab 1: General Purpose IO
Prof. Chung-Ta King Department of Computer Science
ECE 3430 – Intro to Microcomputer Systems
CS4101 嵌入式系統概論 General Purpose IO
Hardware Source: ttp:// under
Instructor: Dr Aleksandar Milenkovic Lecture Notes
MSP432 ARM Timer Programming
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 2: Timer and Clock Prof. Chung-Ta King Department of Computer Science National.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 3: Interrupt Prof. Chung-Ta King Department of Computer Science National Tsing.
National Tsing Hua University CS4101 Introduction to Embedded Systems Lab 6: Serial Communication Prof. Chung-Ta King Department of Computer Science National.
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 7: Serial Communication
CS4101 Introduction to Embedded Systems Lab 4: Interrupt
CS4101 Introduction to Embedded Systems Lab 7: Serial Communication
Lecture 9: TI MSP430 Interrupts & Low Power Modes
ECE 3430 – Intro to Microcomputer Systems
CS4101 Introduction to Embedded Systems Lab 2: Basic IO and Timer
Prof. Chung-Ta King Department of Computer Science
MSP430 Clock System and Timer
ECE 3567 Microcontrollers Lab
ECE 3567 Microcontroller Lab
A modular robot for use in the RoboSumo lab
Presentation transcript:

CS4101 嵌入式系統概論 Software UART Revisited Prof. Chung-Ta King Department of Computer Science National Tsing Hua University, Taiwan ( Materials from MSP430 Microcontroller Basics, John H. Davies, Newnes, 2008 )

1 Sample Code (msp430g2xx3_ta_uart9600)  Software UART, using Timer_A, 9600 baud, echo, full-duplex, SMCLK at 1MHz Main loop readies UART, sends greetings to PC, then repetitively waits to receive one character from PC, and echoes it back to the PC while waiting in LPM0 in between ISR. All activities are interrupt-driven. TACCR0 handles TXD and TACCR1 handles RXD. Both may interrupt the CPU at any time and in an interleaved way.

2 Sample Code (msp430g2xx3_ta_uart9600) #include "msp430g2553.h“ #define UART_TXD 0x02 // TXD on P1.1 (Timer0_A.OUT0) #define UART_RXD 0x04 // RXD on P1.2 (Timer0_A.CCI1A) #define UART_TBIT_DIV_2 ( / (9600 * 2)) #define UART_TBIT ( / 9600) unsigned int txData; // UART internal TX variable unsigned char rxBuffer; // Received UART character void TimerA_UART_init(void); void TimerA_UART_tx(unsigned char byte); void TimerA_UART_print(char *string); void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer DCOCTL = 0x00; // Set DCOCLK to 1MHz BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ;

3 Sample Code (msp430g2xx3_ta_uart9600) P1OUT = 0x00; // Initialize all GPIO P1SEL = UART_TXD + UART_RXD; // Use TXD/RXD pins P1DIR = 0xFF & ~UART_RXD; // Set pins to output __enable_interrupt(); TimerA_UART_init(); // Start Timer_A UART TimerA_UART_print("G2xx2 TimerA UART\r\n"); TimerA_UART_print("READY.\r\n"); for (;;) { __bis_SR_register(LPM0_bits); TimerA_UART_print(“RECEIVED-"); TimerA_UART_tx(rxBuffer); } void TimerA_UART_print(char *string) { while (*string) TimerA_UART_tx(*string++); }

4 4 Sample Code (msp430g2xx3_ta_uart9600) void TimerA_UART_init(void) { TACCTL0 = OUT; // Set TXD Idle as Mark = '1' TACCTL1 = SCS + CM1 + CAP + CCIE; // Sync, Neg Edge, Capture, Int TACTL = TASSEL_2 + MC_2; // SMCLK, continuous mode } void TimerA_UART_tx(unsigned char byte) { while (TACCTL0 & CCIE); // Ensure last char TXed TACCR0 = TAR; // Current state of TA counter TACCR0 += UART_TBIT; // One bit time till first bit TACCTL0 = OUTMOD0 + CCIE; // Set TXD on EQU0, Int txData = byte; // Load global variable txData |= 0x100; // Add mark stop bit to TXData txData <<= 1; // Add space start bit }

5 5 Sample Code (msp430g2xx3_ta_uart9600) #pragma vector = TIMER0_A0_VECTOR __interrupt void Timer_A0_ISR(void) { static unsigned char txBitCnt = 10; TACCR0 += UART_TBIT; // Add Offset to CCRx if (txBitCnt == 0) { // All bits TXed? TACCTL0 &= ~CCIE; // All bits TXed, disable int txBitCnt = 10; // Re-load bit counter } else { if (txData & 0x01) { TACCTL0 &= ~OUTMOD2; // TX Mark '1’ } else { TACCTL0 |= OUTMOD2;} // TX Space '0‘ txData >>= 1; txBitCnt--; }

6 6 Sample Code (msp430g2xx3_ta_uart9600) #pragma vector = TIMER0_A1_VECTOR __interrupt void Timer_A1_ISR(void) { static unsigned char rxBitCnt = 8; static unsigned char rxData = 0; switch (__even_in_range(TA0IV, TA0IV_TAIFG)) { case TA0IV_TACCR1: // TACCR1 CCIFG - UART RX TACCR1 += UART_TBIT; // Add Offset to CCRx if (TACCTL1 & CAP) { // On start bit edge TACCTL1 &= ~CAP; // Switch to compare mode TACCR1 += UART_TBIT_DIV_2; // To middle of D0 } else { // Get next data bit rxData >>= 1;

7 7 Sample Code (msp430g2xx3_ta_uart9600) if (TACCTL1 & SCCI) { // Get bit from latch rxData |= 0x80; } rxBitCnt--; if (rxBitCnt == 0) { // All bits RXed? rxBuffer = rxData; // Store in global rxBitCnt = 8; // Re-load bit counter TACCTL1 |= CAP; // Switch to capture __bic_SR_register_on_exit(LPM0_bits); // Clear LPM0 bits from 0(SR) } break; } Wake up main loop