arm:teensy3
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
arm:teensy3 [2014/04/16 21:32] – [PWM] redox | arm:teensy3 [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | # Teensy 3 | ||
- | ## Overview | ||
- | {{ : | ||
- | |||
- | I already had experience with the Teensy2, but I needed more power, better ADC, ... for a larger project (work, can't tell much more sorry)°. Before going for the Teensy3, I reviewed different ARM breakout boards, but I didn't need any special features or a large board. | ||
- | |||
- | ### Teensy3.1 | ||
- | {{ : | ||
- | |||
- | No more black PCB, but gold plated finish instead of tin plated. You can't have everything, right ?! It's basically a simple CPU upgrade, but you can find more details on [[http:// | ||
- | |||
- | ## Tools | ||
- | |||
- | ### Arduino vs C | ||
- | Well, the only thing that was not really cool (__for me__) with the Teensy3 was there was no toolchain, no libraries, no tutorial whatsoever for one to start coding. | ||
- | |||
- | Paul, from PJRC, has made a really great work to make the Teensy3 fully Arduino-compatible, | ||
- | |||
- | ### Toolchain | ||
- | |||
- | Just a quick note, it's really easy. I'm working with GNU/Linux environments, | ||
- | |||
- | sudo pacman -S arm-none-eabi-gcc arm-none-eabi-binutils | ||
- | |||
- | That's all folks, you're good to go ;) | ||
- | |||
- | On others distros, it should be something really close =) | ||
- | |||
- | ### Teensy Loader CLI | ||
- | |||
- | Once again, Paul made a great USB bootloader. It's even better than the one on the Teensy2, since it's harder to brick; actually, there' | ||
- | |||
- | You need the teensyloadercli software, but, obviously, updated for the Teensy3. It can be found in the [[http:// | ||
- | |||
- | * Start the application with the correct arguments. \\ Like ` ./ | ||
- | * Press the onboard button | ||
- | * Wait until completion | ||
- | * Done ! | ||
- | |||
- | ## LED Blink | ||
- | Or, as it's often called, the _Hello World_ for µC | ||
- | |||
- | Nothing fancy, it just blinks the onboard LED on the Teensy3. The source is here: {{: | ||
- | |||
- | Compile with `make` then program with `make program` (you need the teensyloadercli software in the source folder, I moved it system-wide later I think...). Press the button on your board, it should be flashed and then reboot. The LED blinks ! =D | ||
- | |||
- | ## USB | ||
- | ### HID Debug | ||
- | It should work with the __hid\_listen__ software from PRJC... | ||
- | |||
- | Well, blinking a LED is really cool (I _love_ LEDs)° but the Teensy3 is a bit too-much for doing just that. Moving on to USB, I really liked the usb\_debug\_only feature on the Teensy2, so I though I would do something like that for the Teensy3. | ||
- | |||
- | Digging through my sources, I found I didn't separate the HID Debug and the RawHID I had to develop for the project I was working on so... no separate source here (yet, I hope to fix that someday...). | ||
- | |||
- | ### RawHID | ||
- | |||
- | I needed some USB communication, | ||
- | |||
- | The code provides __usb\_debug__ (through the _hid\_listen_ tool) and __raw\_hid__ (tests with the _rawhid_ tool). It's currently available here: {{: | ||
- | |||
- | <note important> | ||
- | |||
- | ## I2C | ||
- | ### Master | ||
- | ### Slave | ||
- | |||
- | Well, it's a little bit messy sorry, but it's old code for me; and I don't currently have time to clean things up. Two sources: | ||
- | |||
- | * {{: | ||
- | * {{: | ||
- | |||
- | |||
- | ## ADC | ||
- | < | ||
- | uint16_t ADC_Conv(uint8_t ch); | ||
- | static const uint8_t TsyADCtoARMpin[] = { | ||
- | 5, 14, 8, 9, 13, 12, 6, 7, 15, 4, | ||
- | 0, 19, 3, 21, 26, 22}; | ||
- | </ | ||
- | In your main, at initialization: | ||
- | < | ||
- | uint16_t x; | ||
- | ///////////////////////// | ||
- | PORTB_PCR2 = PORT_PCR_MUX(0); | ||
- | PORTB_PCR3 = PORT_PCR_MUX(0); | ||
- | PORTC_PCR1 = PORT_PCR_MUX(0); | ||
- | PORTC_PCR2 = PORT_PCR_MUX(0); | ||
- | PORTD_PCR5 = PORT_PCR_MUX(0); | ||
- | PORTD_PCR6 = PORT_PCR_MUX(0); | ||
- | |||
- | ///// VRef (Chap 33) | ||
- | VREF_TRM = 0x60; | ||
- | VREF_SC = _BV(7) | _BV(6) | _BV(5) | _BV(0); | ||
- | while(!(VREF_SC & _BV(2))); | ||
- | |||
- | ///// ADC Conf | ||
- | SIM_SCGC6 |= SIM_SCGC6_ADC0; | ||
- | ADC0_CFG1 = ADC_CFG1_ADIV(3) | // | ||
- | ADC_CFG1_ADLSMP | // Long Sample time | ||
- | ADC_CFG1_MODE(3) | // | ||
- | ADC_CFG1_ADICLK(1); | ||
- | ADC0_CFG2 = ADC_CFG2_MUXSEL + ADC_CFG2_ADLSTS(0); | ||
- | ADC0_SC2 = ADC_SC2_REFSEL(0); | ||
- | |||
- | ///// Cal (Follows the Datasheet instructions) | ||
- | ADC0_SC3 = ADC_SC3_CAL + ADC_SC3_AVGE + ADC_SC3_AVGS(3); | ||
- | while(ADC0_SC3 & ADC_SC3_CAL); | ||
- | |||
- | x = 0; | ||
- | x = ADC0_CLP0 + ADC0_CLP1 + ADC0_CLP2 + ADC0_CLP3 + ADC0_CLP4 + ADC0_CLPS; | ||
- | x = x/2 | _BV(15); | ||
- | ADC0_PG = x; | ||
- | |||
- | x = ADC0_CLM0 + ADC0_CLM1 + ADC0_CLM2 + ADC0_CLM3 + ADC0_CLM4 + ADC0_CLMS; | ||
- | x = x/2 | _BV(15); | ||
- | ADC0_MG = x; | ||
- | </ | ||
- | After the main: | ||
- | < | ||
- | /* In: ADCn pin to sample | ||
- | Out: 16bits unsigned result | ||
- | */ | ||
- | uint16_t ADC_Conv(uint8_t ch) { | ||
- | ADC0_SC1A = TsyADCtoARMpin[ch]; | ||
- | while (!(ADC0_SC1A & ADC_SC1_COCO)); | ||
- | return ADC0_RA; | ||
- | } | ||
- | </ | ||
- | In the main, when you need an ADC conversion: | ||
- | < | ||
- | TempSense = ADC_Conv(_TSY_PIN_); | ||
- | </ | ||
- | |||
- | |||
- | ## PWM | ||
- | < | ||
- | ///////////////////////// | ||
- | PORTA_PCR12 = PORT_PCR_MUX(3)|PORT_PCR_SRE; | ||
- | PORTA_PCR13 = PORT_PCR_MUX(3)|PORT_PCR_SRE; | ||
- | PORTC_PCR3 = PORT_PCR_MUX(4)|PORT_PCR_SRE; | ||
- | PORTD_PCR4 = PORT_PCR_MUX(4)|PORT_PCR_SRE; | ||
- | PORTD_PCR7 = PORT_PCR_MUX(4)|PORT_PCR_SRE; | ||
- | |||
- | SIM_SCGC6 |= SIM_SCGC6_FTM0|SIM_SCGC6_FTM1; | ||
- | |||
- | FTM0_CNT = 0; FTM1_CNT = 0; | ||
- | FTM0_MOD = 0xFFFF; FTM1_MOD = 0xFFFF; | ||
- | | ||
- | FTM1_C0SC = 0x28; | ||
- | FTM1_C1SC = 0x28; | ||
- | FTM0_C2SC = 0x28; | ||
- | FTM0_C4SC = 0x28; | ||
- | FTM0_C7SC = 0x28; | ||
- | FTM0_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0); | ||
- | FTM1_SC = FTM_SC_CLKS(1) | FTM_SC_PS(0); | ||
- | FTM0_MODE &= ~FTM_MODE_WPDIS; | ||
- | |||
- | FTM1_C0V = 32767; //Example | ||
- | </ | ||
- | |||
- | ## Links | ||
- | |||
- | * [[http:// | ||
- | * [[http:// | ||
/home/share/www/redox.ws/wiki/data/attic/arm/teensy3.1397683968.txt.gz · Last modified: 2023/11/24 21:55 (external edit)