#include <msp430.h>
#define OUTPUT_PIN BIT0
/*
* main.c
*
* Testing timer_0 interrupt to toggle LED (P1.0)
*/
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= OUTPUT_PIN; // Set P1.0 and P1.6 to output direction
P1OUT |= OUTPUT_PIN;
P1OUT ^= (OUTPUT_PIN);
BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ;
CCTL0 = CCIE;
TACTL = TASSEL_2 + ID_3 + MC_1; // Set the timer A to SMCLCK, UP to TACCR0, Input Divider: /8
TACCR0 = 50000-1; // 50ms @(8MHz/8)
__enable_interrupt();
__bis_SR_register(LPM0 + GIE); // LPM0 with interrupts enabled
while(1);
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
static unsigned char ucCount = 0;
if(ucCount++ >= 20){
P1OUT ^= OUTPUT_PIN;
ucCount = 0;
}
}
2016年10月24日 星期一
MSP430 LaunchPad Timer_0 Interrupt
Using Timer_0 Interrupt to Toggle LED on MSP430 LaunchPad
2016年3月2日 星期三
TI CCStudio Bit-Field Definitions
Bit-Field Definitions
- Bit field members are stored from right to left in memory. (LSB 開始放置)
例如:
struct SCICCR_BITS { // bit description
Uint16 SCICHAR:3; // 2:0 Character length control (LSB)
Uint16 ADDRIDLE_MODE:1; // 3 ADDR/IDLE Mode control
Uint16 LOOPBKENA:1; // 4 Loop Back enable
Uint16 PARITYENA:1; // 5 Parity enable
Uint16 PARITY:1; // 6 Even or Odd Parity
Uint16 STOPBITS:1; // 7 Number of Stop Bits
Uint16 rsvd1:8; // 15:8 reserved
};
- The C28x compiler limits the maximum number of bits within a bit field to the size of an integer; no bit field can be greater than 16 bits in length.
- If the total number of bits defined by bit fields within a structure grows above 16 bits, then the next bit field is stored consecutively in the next word of memory.
要注意的是, 例如寫入單一個成員變數, CPU 是執行 read-modify-write; 也就是說在有些 register 寫入 1 是清除的指令, 當成員變數在同一個 structure 中時, 寫入 A 成員, 可能會造成 B 成員也被清除. 這時候可能要用整個 structure 寫入的方式.
以下的 register 在執行 read-modify-write 動作時, 要注意:
1) Registers with bits that hardware can change after the read, but before the write
2) Registers with write 1-to-clear bits
3) Registers that have bits that must be written with a value different from what the bits read back
ref: TI SPRAA85D, Programming TMS320x28xx and 28xxx Peripherals in C/C++ (Rev. D)
p.16
- Bit field members are stored from right to left in memory. (LSB 開始放置)
例如:
struct SCICCR_BITS { // bit description
Uint16 SCICHAR:3; // 2:0 Character length control (LSB)
Uint16 ADDRIDLE_MODE:1; // 3 ADDR/IDLE Mode control
Uint16 LOOPBKENA:1; // 4 Loop Back enable
Uint16 PARITYENA:1; // 5 Parity enable
Uint16 PARITY:1; // 6 Even or Odd Parity
Uint16 STOPBITS:1; // 7 Number of Stop Bits
Uint16 rsvd1:8; // 15:8 reserved
};
- The C28x compiler limits the maximum number of bits within a bit field to the size of an integer; no bit field can be greater than 16 bits in length.
- If the total number of bits defined by bit fields within a structure grows above 16 bits, then the next bit field is stored consecutively in the next word of memory.
要注意的是, 例如寫入單一個成員變數, CPU 是執行 read-modify-write; 也就是說在有些 register 寫入 1 是清除的指令, 當成員變數在同一個 structure 中時, 寫入 A 成員, 可能會造成 B 成員也被清除. 這時候可能要用整個 structure 寫入的方式.
以下的 register 在執行 read-modify-write 動作時, 要注意:
1) Registers with bits that hardware can change after the read, but before the write
2) Registers with write 1-to-clear bits
3) Registers that have bits that must be written with a value different from what the bits read back
ref: TI SPRAA85D, Programming TMS320x28xx and 28xxx Peripherals in C/C++ (Rev. D)
p.16
2015年9月29日 星期二
Energia : using hardware UART
Using LaunchPad MSP-EXP430G2
MCU: M430G2553
problem:
Serial Monitor can't get the data from LaunchPad
Solution:
Connecting to the USB2.0 hub port instead of connecting to USB3.0 port. If it still not works, trying another USB2.0 hub port.
使用 LaunchPad 時, Serial Monitor 一直無法看到 UART 傳來的資料.
後來使用 USB2.0 hub 連接 LaunchPad , Serial Monitor 就可收到 UART 的資料.
MCU: M430G2553
problem:
Serial Monitor can't get the data from LaunchPad
Solution:
Connecting to the USB2.0 hub port instead of connecting to USB3.0 port. If it still not works, trying another USB2.0 hub port.
使用 LaunchPad 時, Serial Monitor 一直無法看到 UART 傳來的資料.
後來使用 USB2.0 hub 連接 LaunchPad , Serial Monitor 就可收到 UART 的資料.
訂閱:
文章 (Atom)