Une fois le launchpad branché sur l'USB on vérifie qu'il est bien là :
Code : Tout sélectionner
>lsusb
...
Bus 006 Device 002: ID 0451:f432 Texas Instruments, Inc.
...
et quel est le microcontôleur inséré :
Code : Tout sélectionner
>sudo mspdebug rf2500
Trying to open interface 1 on 002
Initializing FET...
FET protocol version is 30066536
Configured for Spy-Bi-Wire
Set Vcc: 3000 mV
Device ID: 0xf201
Device: MSP430F2012 <---------------- ICI
Code memory starts at 0xf800
Number of breakpoints: 2
fet: FET returned NAK
fet: warning: message 0x30 failed
Code : Tout sélectionner
#include <msp430x20x2.h>Code : Tout sélectionner
msp430-gcc -mmcu=msp430x2012 -o msp430.elf msp430.c
Code : Tout sélectionner
prog msp430.elf
Erasing...
Programming...
Writing 638 bytes to f800 [section: .text]...
Writing 72 bytes to fa7e [section: .data]...
Writing 32 bytes to ffe0 [section: .vectors]...
Code : Tout sélectionner
run
Running. Press Ctrl+C to interrupt...
- avant, pas entier
- avant, demi pas
- arrêt
- arrière, demi pas
- arrière, pas entier
- arrêt
Pour finir, voici le code (fichier msp430.c), qu'il faudra légèrement modifier si l'on choisi Window$ et l'environnement de développement fournit par TI.
Code : Tout sélectionner
#include <msp430x20x2.h>
#include <signal.h>
#include <io.h>
#define RED_LED BIT0
#define GREEN_LED BIT6
#define A1 BIT1
#define B1 BIT2
#define C1 BIT4
#define D1 BIT5
#define LED_DIR P1DIR
#define LED_OUT P1OUT
#define BUTTON BIT3
#define BUTTON_DIR P1DIR
#define BUTTON_OUT P1OUT
#define BUTTON_IN P1IN
#define BUTTON_REN P1REN
#define BUTTON_INTERUPT P1IE
int aState[]={A1,A1,0, 0, 0, 0, 0, A1};
int bState[]={0, B1,B1,B1,0, 0, 0, 0 };
int cState[]={0, 0, 0, C1,C1,C1,0, 0 };
int dState[]={0, 0, 0, 0, 0, D1,D1,D1};
int position = 0;
int direction = 0;
int half = 0;
int action = 0;
void off(void){
LED_OUT = LED_OUT&(RED_LED|GREEN_LED)|(0);
}
// Half step
void halfStep(void){
position += direction > 0 ? +1 : -1;
if(position>7)position=0;
if(position<0)position=7;
LED_OUT = LED_OUT&(RED_LED|GREEN_LED)|(aState[position] | bState[position] | cState[position] | dState[position]);
}
// One step
void oneStep(void){
position = ((position * 2) + 1) / 2 ;
position += direction > 0 ? +2 : -2;
if(position>6)position=0;
if(position<0)position=6;
LED_OUT = LED_OUT&(RED_LED|GREEN_LED)|(aState[position] | bState[position] | cState[position] | dState[position]);
}
// Port 1 interrupt service routine
interrupt(PORT1_VECTOR) Port_1(void){
action++;
if(action>5)action=0;
switch(action){
case 0:
direction = 0;
break;
case 1:
half = 0;
direction = +1;
break;
case 2:
half = 1;
direction = +1;
break;
case 3:
direction = 0;
break;
case 4:
half = 0;
direction = -1;
break;
case 5:
half = 1;
direction = -1;
break;
}
LED_OUT ^= RED_LED|GREEN_LED;
P1IFG &= ~BUTTON; // P1.3 IFG cleared
}
// Main program
int main(void){
int i;
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
LED_DIR |= RED_LED | GREEN_LED | A1 | B1 | C1 | D1; // Set output direction
LED_OUT &= ~(RED_LED | GREEN_LED | A1 | B1 | C1 | D1); // Set output to 0
P1IE |= BUTTON; // P1.3 interrupt enabled
P1IES |= BUTTON; // P1.3 Hi/lo edge
P1IFG &= ~BUTTON; // P1.3 IFG cleared
_BIS_SR(GIE);
for(;;){
if(direction==0)
off();
else
if(half==1)
halfStep();
else
oneStep();
for (i=0;i<10000;i++)
nop();
}
}


