I am moving gradually to the new ARMv7M variant, and specifically the Luminary chips. I have a dev board in the mail to me (LM3S811, $49 for the board, with a OLED display and can function like a jtag adapter should I move onto something else).
I had played with LPCs before but those Luminary beasts are totally different in how they are setting up, and sample code is hard to come by.
so it took me an entire morning to get something going.
it is a way to blink 3 strings of LEDs on port A, port C and port D:
on port A, we are just blinking the last four leds:
on port C, we are rolling leds from the lowest bit to the highest bit.
on port D, we are just incrementing the leds, linearly.
the weird thing about those luminary chips is the rcgc registers. in particular, we have to run the clocks to the ports before we can use them. that took me a while to figure out, .
so here it is. if someone is using the luminary chips, you don't have to waste a morning to figure that out.
I had played with LPCs before but those Luminary beasts are totally different in how they are setting up, and sample code is hard to come by.
so it took me an entire morning to get something going.
Rich (BB code):
#include <lm3s811.h>
#define PORTA_ENABLED 0x01
#define PORTB_ENABLED 0x02
#define PORTC_ENABLED 0x04
#define PORTD_ENABLED 0x08
#define PORTE_ENABLED 0x0f
//hardware configuration
#define LED1 GPIO_PORTA_DATA_R //1st led string on porta
#define LED2 GPIO_PORTC_DATA_R //2nd led string on partc
#define LED3 GPIO_PORTD_DATA_R //2nd led string on partd
void init_mcu(void) {
SYSCTL_RCGC2_R=PORTA_ENABLED | PORTC_ENABLED | PORTD_ENABLED; //enable gate a, c and d;
//set up porta
GPIO_PORTA_DIR_R=0x0f; //lowest four bits for output
GPIO_PORTA_DEN_R=0x0f; //lowest four bits enabled for digital
GPIO_PORTA_AFSEL_R=0x00; //no alternative functions on all 8 bits
GPIO_PORTA_DATA_R=0x55; //output set to 0b01010101. But only last four bits used due to DIR_R setting
//set up portc
GPIO_PORTC_DIR_R=0xff; //all 8 bits for output
GPIO_PORTC_DEN_R=0xff; //all 8 bits enabled for digital
GPIO_PORTC_AFSEL_R=0x00; //no alternative functions on all 8 bits
GPIO_PORTC_DATA_R=0x01; //output set to 0b00000001. But only last four bits used due to DIR_R setting
//set up portd
GPIO_PORTD_DIR_R=0xff; //all 8 bits for output
GPIO_PORTD_DEN_R=0xff; //all 8 bits enabled for digital
GPIO_PORTD_AFSEL_R=0x00; //no alternative functions on all 8 bits
GPIO_PORTD_DATA_R=0x01; //output set to 0b00000001. But only last four bits used due to DIR_R setting
}
void delay(int dly) {
for (; dly>0; dly--)
;
}
int main(void) {
int LED2_i=1;
int LED3_i=1;
init_mcu();
while (1) {
delay(5000);
LED1=~LED1; //blinking led1
LED2=LED2_i;
if (LED2_i==0x80) //if the left most bit is on
LED2_i=1; //reset to to the right most bit
else
LED2_i<<=1; //otherwise, shift to the left by 1 bit
LED3=LED3_i;
if (LED3_i==0xff) //if all leds are on
LED3_i=0; //turn all LEDs off
else
LED3_i=LED3_i+1; //increment by 1;
}
}
on port A, we are just blinking the last four leds:
on port C, we are rolling leds from the lowest bit to the highest bit.
on port D, we are just incrementing the leds, linearly.
the weird thing about those luminary chips is the rcgc registers. in particular, we have to run the clocks to the ports before we can use them. that took me a while to figure out, .
so here it is. if someone is using the luminary chips, you don't have to waste a morning to figure that out.