You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I started with microchip's own "TB3214-Getting-Started-with-TCB-90003214A.pdf". in "Example 7-3. TCB Sleep Mode Operation Code Example" I followed their example as closely as I can possibly get in my custom board (one with an RGB LED). The board goes into low power - no CPU - but no LED blinking from the TCB timer interrupt. I have no idea where to turn next.
Here's my code - with changes from the example noted in comments:
void PORT_init (void)
{
RGB_R_PORT.DIR |= RGB_R_PIN; /* Change from example /
RGB_G_PORT.DIR |= RGB_G_PIN; / Change from example /
RGB_B_PORT.DIR |= RGB_B_PIN; / Change from example */
}
void setRed(bool state) /* Change from example */
{
if (state)
RGB_R_PORT.OUT |= RGB_R_PIN;
else
RGB_R_PORT.OUT &= ~RGB_R_PIN;
}
void setGreen(bool state) /* Change from example */
{
if (state)
RGB_G_PORT.OUT |= RGB_G_PIN;
else
RGB_G_PORT.OUT &= ~RGB_G_PIN;
}
void setBlue(bool state) /* Change from example */
{
if (state)
RGB_B_PORT.OUT |= RGB_B_PIN;
else
RGB_B_PORT.OUT &= ~RGB_B_PIN;
}
void TCB0_init (void)
{
/* Load the Compare or Capture register with the timeout value*/
TCB0.CCMP = TCB_CMP_EXAMPLE_VALUE;
/* Enable TCB and set CLK_PER divider to 1 (No Prescaling) /
TCB0.CTRLA = TCB_CLKSEL_CLKDIV1_gc | TCB_ENABLE_bm | TCB_RUNSTDBY_bm;
/ Enable Capture or Timeout interrupt */
TCB0.INTCTRL = TCB_CAPT_bm;
}
ISR(TCB0_INT_vect)
{
TCB0.INTFLAGS = TCB_CAPT_bm; /* Clear the interrupt flag /
// setRed(true);
PORTE.IN = RGB_R_PIN; / Toggle PBE GPIO / / Change from example */
}
int main(void)
{
CLOCK_init();
SLPCTRL_init();
PORT_init();
TCB0_init();
sei(); /* Enable Global Interrupts */
setRed(false); /* Change from example - change the LEDs to off */
setGreen(false); /* Change from example */
setBlue(false); /* Change from example */
while (1)
{
sleep_mode();
}
}
ANY CLUES?
The text was updated successfully, but these errors were encountered:
I started with microchip's own "TB3214-Getting-Started-with-TCB-90003214A.pdf". in "Example 7-3. TCB Sleep Mode Operation Code Example" I followed their example as closely as I can possibly get in my custom board (one with an RGB LED). The board goes into low power - no CPU - but no LED blinking from the TCB timer interrupt. I have no idea where to turn next.
Here's my code - with changes from the example noted in comments:
#include <atmel_start.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#define TCB_CMP_EXAMPLE_VALUE (0x7FFF)
#define RGB_R_PORT VPORTE /* Change from example /
#define RGB_R_PIN PIN0_bm / Change from example */
#define RGB_G_PORT VPORTE /* Change from example /
#define RGB_G_PIN PIN1_bm / Change from example */
#define RGB_B_PORT VPORTE /* Change from example /
#define RGB_B_PIN PIN2_bm / Change from example */
void CLOCK_init (void);
void SLPCTRL_init (void);
void PORT_init (void);
void TCB0_init (void);
void CLOCK_init (void)
{
/* Enable writing to protected register /
CPU_CCP = CCP_IOREG_gc;
/ Disable CLK_PER Prescaler /
CLKCTRL.MCLKCTRLB = 0 << CLKCTRL_PEN_bp;
/ Enable writing to protected register /
CPU_CCP = CCP_IOREG_gc;
/ Select 32KHz Internal Ultra Low Power Oscillator (OSCULP32K) /
CLKCTRL.MCLKCTRLA = CLKCTRL_CLKSEL_OSCULP32K_gc;
/ Wait for system oscillator changing to finish */
while (CLKCTRL.MCLKSTATUS & CLKCTRL_SOSC_bm)
{
;
}
}
void SLPCTRL_init (void)
{
/* Enable sleep mode and select Standby mode */
SLPCTRL.CTRLA = SLPCTRL_SMODE_gm | SLPCTRL_SMODE_STDBY_gc;
}
void PORT_init (void)
{
RGB_R_PORT.DIR |= RGB_R_PIN; /* Change from example /
RGB_G_PORT.DIR |= RGB_G_PIN; / Change from example /
RGB_B_PORT.DIR |= RGB_B_PIN; / Change from example */
}
void setRed(bool state) /* Change from example */
{
if (state)
RGB_R_PORT.OUT |= RGB_R_PIN;
else
RGB_R_PORT.OUT &= ~RGB_R_PIN;
}
void setGreen(bool state) /* Change from example */
{
if (state)
RGB_G_PORT.OUT |= RGB_G_PIN;
else
RGB_G_PORT.OUT &= ~RGB_G_PIN;
}
void setBlue(bool state) /* Change from example */
{
if (state)
RGB_B_PORT.OUT |= RGB_B_PIN;
else
RGB_B_PORT.OUT &= ~RGB_B_PIN;
}
void TCB0_init (void)
{
/* Load the Compare or Capture register with the timeout value*/
TCB0.CCMP = TCB_CMP_EXAMPLE_VALUE;
/* Enable TCB and set CLK_PER divider to 1 (No Prescaling) /
TCB0.CTRLA = TCB_CLKSEL_CLKDIV1_gc | TCB_ENABLE_bm | TCB_RUNSTDBY_bm;
/ Enable Capture or Timeout interrupt */
TCB0.INTCTRL = TCB_CAPT_bm;
}
ISR(TCB0_INT_vect)
{
TCB0.INTFLAGS = TCB_CAPT_bm; /* Clear the interrupt flag /
// setRed(true);
PORTE.IN = RGB_R_PIN; / Toggle PBE GPIO / / Change from example */
}
int main(void)
{
CLOCK_init();
SLPCTRL_init();
PORT_init();
TCB0_init();
sei(); /* Enable Global Interrupts */
}
ANY CLUES?
The text was updated successfully, but these errors were encountered: