Last active
April 13, 2024 20:53
-
-
Save todbot/7d84ba8c4ae204b49a76d71b723fccc3 to your computer and use it in GitHub Desktop.
samd21 blink LED in C, no SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// originally from: https://github.com/dwelch67/atsamd_samples/tree/master/ATSAMD21/sparkfun/blinker01 | |
#include <stdint.h> // for uint32_t | |
int main(void) { | |
unsigned int ra; | |
unsigned int rx; | |
uint32_t* PORT_A_DIR = (uint32_t*)0x41004400; // "PORT" from Table 12-1 & 23.7 of SAMD21 Datasheet | |
uint32_t* PORT_A_OUT = (uint32_t*)(0x41004400 + 0x10); // from 23.7 "Register Summary" of SAMD21 Datasheet | |
*PORT_A_DIR |= ( 1 << 10 ); // PA10 is red LED on Trinket | |
*PORT_A_OUT |= ( 1 << 10 ); | |
for(rx=0;;rx++) { | |
*PORT_A_OUT |= ( 1 << 10 ); | |
for(ra=0;ra<80000;ra++) { asm("nop"); } | |
*PORT_A_OUT &=~ ( 1 << 10 ); | |
for(ra=0;ra<20000;ra++) { asm("nop"); } | |
} | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment