EDIT: helps if I use the ground from the board instead of the 12V in for the board I am soldering up!
First of all this is the first arm board I've ever programmed so have mercy on me.
I have configured two pins PTB16 and PTB17 (it looks like the quick reference doc in the cardboard box got them the wrong way round as they correspond as below I am yet to double check this against the RM etc)
//define two pins for vcc1 and vcc2 #define VALVE_VCC1_PIN 16U //PTB17 #define VALVE_VCC1_GPIO GPIOB #define VALVE_VCC1_PORT PORTB #define VALVE_VCC2_PIN 17U //PTB16 #define VALVE_VCC2_GPIO GPIOB #define VALVE_VCC2_PORT PORTB
So I've configured them in pin_mux.c
CLOCK_EnableClock(kCLOCK_PortA); PORT_SetPinMux(VALVE_VCC1_PORT, VALVE_VCC1_PIN, kPORT_MuxAsGpio); PORT_SetPinMux(VALVE_VCC2_PORT, VALVE_VCC2_PIN, kPORT_MuxAsGpio);
Then in main.c I init the pins
/* Output pin configuration */ gpio_pin_config_t valve_config = { kGPIO_DigitalOutput, 1, }; /* Sets the configuration */ void initState() { GPIO_PinInit(VALVE_VCC1_GPIO, VALVE_VCC1_PIN, &valve_config); GPIO_PinInit(VALVE_VCC2_GPIO, VALVE_VCC2_PIN, &valve_config); }
Then I use the GPIO_TogglePinsOutput functions to turn them on, which individually if I only do one, works. however if I do both they both fail.
//stop when flow is going. void openValve() { GPIO_TogglePinsOutput(VALVE_VCC2_GPIO, 1U << VALVE_VCC2_PIN); } //stop when flow stops void closeValve() { GPIO_TogglePinsOutput(VALVE_VCC1_GPIO, 1U << VALVE_VCC1_PIN); }
I have no idea why and I don't own a jlink debugger (however work does have one) am using KDS studio
I am doing this project for fun and it would be great to learn how to use this board better.
lastly thank you!
Hi, Michael,
I have checked the function:
static inline void GPIO_TogglePinsOutput(GPIO_Type *base, uint32_t mask)
{
base->PTOR = mask;
}
I do not think there is any issue if you call both GPIO_TogglePinsOutput(VALVE_VCC2_GPIO, 1U << VALVE_VCC2_PIN); and GPIO_TogglePinsOutput(VALVE_VCC1_GPIO, 1U << VALVE_VCC1_PIN);
I suggest you add the line for example __asm("nop"); and set a break point after you call the above function, and check the logic or LED state.
you can also toggle two pins with the code
GPIO_TogglePinsOutput(VALVE_VCC2_GPIO, (1U << VALVE_VCC2_PIN)|(1U << VALVE_VCC1_PIN)); //what is the result?
BTW, you said "however if I do both they both fail.", what is the failure?
Hope it can hep you.
BR
Xiangjun Rong
GPIO_TogglePinsOutput(VALVE_VCC2_GPIO, 1U << VALVE_VCC2_PIN); //
__asm("nop"); //set a break point
GPIO_TogglePinsOutput(VALVE_VCC1_GPIO, 1U << VALVE_VCC1_PIN);
__asm("nop"); //set a break point