Hello,
I am trying to get my feet on the ground with the little $12 Freedom board with basic bit IO.
Debug shows the bits are changing but nothing happens... no LED... nothing on the meter.
Obviously I am missing something...
please help.
thanks
Richard
CODE:
typedef union { unsigned long all;
struct {
unsigned long PIN0:1;
unsigned long PIN1:1;
unsigned long PIN2:1;
unsigned long PIN3:1;
unsigned long PIN4:1;
unsigned long PIN5:1;
unsigned long PIN6:1;
unsigned long PIN7:1;
unsigned long PIN8:1;
unsigned long PIN9:1;
unsigned long PIN10:1;
unsigned long PIN11:1;
unsigned long PIN12:1;
unsigned long PIN13:1;
unsigned long PIN14:1;
unsigned long PIN15:1;
unsigned long PIN16:1;
unsigned long PIN17:1;
unsigned long PIN18:1;
unsigned long PIN19:1;
unsigned long PIN20:1;
unsigned long PIN21:1;
unsigned long PIN22:1;
unsigned long PIN23:1;
unsigned long PIN24:1;
unsigned long PIN25:1;
unsigned long PIN26:1;
unsigned long PIN27:1;
unsigned long PIN28:1;
unsigned long PIN29:1;
unsigned long PIN30:1;
unsigned long PIN31:1;
}bit;
}port_t;
#define P_A ((port_t *) 0x400ff000)
#define P_A_S ((port_t *) 0x400ff004)
#define P_A_C ((port_t *) 0x400ff008)
#define P_A_T ((port_t *) 0x400ff00C)
#define P_A_I ((port_t *) 0x400ff010)
#define P_A_D ((port_t *) 0x400ff014)
#define P_B ((port_t *) 0x400ff040)
#define P_B_S ((port_t *) 0x400ff044)
#define P_B_C ((port_t *) 0x400ff048)
#define P_B_T ((port_t *) 0x400ff04C)
#define P_B_I ((port_t *) 0x400ff050)
#define P_B_D ((port_t *) 0x400ff054)
#define P_C ((port_t *) 0x400ff080)
#define P_C_S ((port_t *) 0x400ff084)
#define P_C_C ((port_t *) 0x400ff088)
#define P_C_T ((port_t *) 0x400ff08C)
#define P_C_I ((port_t *) 0x400ff090)
#define P_C_D ((port_t *) 0x400ff094)
#define P_D ((port_t *) 0x400ff0C0)
#define P_D_S ((port_t *) 0x400ff0C4)
#define P_D_C ((port_t *) 0x400ff0C8)
#define P_D_T ((port_t *) 0x400ff0CC)
#define P_D_I ((port_t *) 0x400ff0D0)
#define P_D_D ((port_t *) 0x400ff0D4)
#define P_E ((port_t *) 0x400ff100)
#define P_E_S ((port_t *) 0x400ff104)
#define P_E_C ((port_t *) 0x400ff108)
#define P_E_T ((port_t *) 0x400ff10C)
#define P_E_I ((port_t *) 0x400ff110)
#define P_E_D ((port_t *) 0x400ff114)
int main(void)
{
unsigned long b1;
unsigned long cnt=0;
b1=P_D_D->bit.PIN1=1;
b1=P_B_D->bit.PIN0=1;
b1=P_E_D->bit.PIN20=1;
while(1)
{
for(cnt = 0; cnt < 126000; cnt++)
{
b1=P_D->bit.PIN1=0;
b1=P_B->bit.PIN0=0;
b1=P_E->bit.PIN20=0;
}
for(cnt = 0; cnt < 126000; cnt++)
{
b1=P_D->bit.PIN1=1;
b1=P_B->bit.PIN0=1;
b1=P_E->bit.PIN20=1;
}
}
}
已解决! 转到解答。
found the answer... I needed some initializations:
/* disable COP */
SIM_COPC = 0;
/* enable clocks for PORTB, PORTD and PORTE */
SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;
SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK;
SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK;
/* set B18, B19, D1 to GPIO */
PORTB_PCR18 = PORT_PCR_MUX(1);
PORTB_PCR19 = PORT_PCR_MUX(1);
PORTD_PCR1 = PORT_PCR_MUX(1);
PORTB_PCR0 = PORT_PCR_MUX(1);
PORTE_PCR20 = PORT_PCR_MUX(1);
works now
found the answer... I needed some initializations:
/* disable COP */
SIM_COPC = 0;
/* enable clocks for PORTB, PORTD and PORTE */
SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;
SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK;
SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK;
/* set B18, B19, D1 to GPIO */
PORTB_PCR18 = PORT_PCR_MUX(1);
PORTB_PCR19 = PORT_PCR_MUX(1);
PORTD_PCR1 = PORT_PCR_MUX(1);
PORTB_PCR0 = PORT_PCR_MUX(1);
PORTE_PCR20 = PORT_PCR_MUX(1);
works now
Hi,
Good luck with your project!! That is right, all the modules need its clock gate enable and SIM_SCGCx contains the field to do that for each module.
Also each pin has different functions that is why you need to configure the Pin Assignments.
Regards.