Part Number:MSP432E401Y
我用的是MSP432E401Y系列,现在只能读取到PL0的I/O,其他四个均无法读取,请问有人知道这是什么原因吗?
#include #include #include "ti/devices/msp432e4/driverlib/driverlib.h" #include "delay.h" #define MIN_DUTY 20 #define MID_DUTY 30 #define MAX_DUTY 40 #define GPIO_PIN_RESET 0 #define GPIO_PIN_SET 1 //#define TURN_LEFT_TIME 1100 //#define TURN_RIGHT_TIME 1100 #define TURN_SMALL 100 #define TURN_BIG 300 #define BUZZER_ON GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1); #define BUZZER_OFF GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x0); #define READ_L2 GPIOPinRead(GPIO_PORTL_BASE, GPIO_PIN_0) #define READ_L1 GPIOPinRead(GPIO_PORTL_BASE, GPIO_PIN_1) #define READ_M GPIOPinRead(GPIO_PORTL_BASE, GPIO_PIN_2) #define READ_R1 GPIOPinRead(GPIO_PORTL_BASE, GPIO_PIN_3) #define READ_R2 GPIOPinRead(GPIO_PORTL_BASE, GPIO_PIN_4) uint8_t dir = 0; // uint16_t pwmcnt = 0; #ifdef DEBUG void __error__(char *pcFilename, uint32_t ui32Line) {while (1); } #endif /*驱动板接线 电机 P27-PG1 PWML P26-PK4 PWMR*/ void delay(uint32_t us) {volatile uint32_t ui32Loop; // Enable the GPIO port that is used for the on-board LED.us *= 20;for (ui32Loop = 0; ui32Loop < us; ui32Loop++){} } void key_init(void) {SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0);GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_1);GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_1,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); } uint8_t scankeys() {if (GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_0) == GPIO_PIN_RESET){dir = 0;return 1;}else if (GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_1) == GPIO_PIN_RESET){dir = 1;return 1;}elsereturn 0; } void lpwm_init() {MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);while (!(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0)));MAP_PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);while (!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF));MAP_GPIOPinConfigure(GPIO_PF0_M0PWM0);MAP_GPIOPinConfigure(GPIO_PF1_M0PWM1);MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, (GPIO_PIN_0 | GPIO_PIN_1));MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 64000);MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0,MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) / 4);MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1,MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_0) / 4);// MAP_IntMasterEnable();// MAP_PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0,//PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD |//PWM_INT_CNT_AU | PWM_INT_CNT_AD);// MAP_IntEnable(INT_PWM0_0);// MAP_PWMIntEnable(PWM0_BASE, PWM_INT_GEN_0);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true); } void rpwm_init() {MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);while (!(MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_PWM0)));MAP_PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);while (!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF));MAP_GPIOPinConfigure(GPIO_PF2_M0PWM2);MAP_GPIOPinConfigure(GPIO_PF3_M0PWM3);MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, (GPIO_PIN_2 | GPIO_PIN_3));MAP_PWMGenConfigure(PWM0_BASE, PWM_GEN_1, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC);MAP_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_1, 64000);MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2,MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_1) / 4);MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3,MAP_PWMGenPeriodGet(PWM0_BASE, PWM_GEN_1) / 4);// MAP_IntMasterEnable();// MAP_PWMGenIntTrigEnable(PWM0_BASE, PWM_GEN_0,//PWM_INT_CNT_ZERO | PWM_INT_CNT_LOAD |//PWM_INT_CNT_AU | PWM_INT_CNT_AD);// MAP_IntEnable(INT_PWM0_0);// MAP_PWMIntEnable(PWM0_BASE, PWM_INT_GEN_0);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT | PWM_OUT_3_BIT, true); } // void PWM0_0_IRQHandler(void) //{ //uint32_t getIntStatus; //getIntStatus = MAP_PWMGenIntStatus(PWM0_BASE, PWM_GEN_0, true); //MAP_PWMGenIntClear(PWM0_BASE, PWM_GEN_0, getIntStatus); // } // 0左前1右前2左后3右后 void duty_set_l(uint8_t dutyl) {MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 640 * dutyl);MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 640 * dutyl); } void duty_set_r(uint8_t dutyr) {MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 640 * dutyr);MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, 640 * dutyr); } void duty_set_all(uint8_t duty) {MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 640 * duty);MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, 640 * duty);MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_2, 640 * duty);MAP_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_3, 640 * duty); } void car_front() {duty_set_all(MID_DUTY);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, false);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, false); } void car_back() {duty_set_all(MID_DUTY);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, false);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, false);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, true); } void car_right() {duty_set_all(MAX_DUTY);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, false);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, false);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, true); } void car_left() {duty_set_all(MAX_DUTY);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, false);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, true);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, true);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, false); } void brake() {duty_set_all(0);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, false);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_1_BIT, false);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_2_BIT, false);MAP_PWMOutputState(PWM0_BASE, PWM_OUT_3_BIT, false); } void gs_init() {MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);while (!MAP_SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOL));MAP_GPIOPinTypeGPIOInput(GPIO_PORTL_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4));// MAP_GPIOPadConfigSet(GPIO_PORTL_BASE, (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4),GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);// GPIOPinTypeGPIOInput(GPIO_PORTL_BASE, GPIO_PIN_0);// GPIOPadConfigSet(GPIO_PORTL_BASE, GPIO_PIN_0,//GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);// GPIOPinTypeGPIOInput(GPIO_PORTL_BASE, GPIO_PIN_1);// GPIOPadConfigSet(GPIO_PORTL_BASE, GPIO_PIN_1,//GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);// GPIOPinTypeGPIOInput(GPIO_PORTL_BASE, GPIO_PIN_2);// GPIOPadConfigSet(GPIO_PORTL_BASE, GPIO_PIN_2,//GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);// GPIOPinTypeGPIOInput(GPIO_PORTL_BASE, GPIO_PIN_3);// GPIOPadConfigSet(GPIO_PORTL_BASE, GPIO_PIN_3,//GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);// GPIOPinTypeGPIOInput(GPIO_PORTL_BASE, GPIO_PIN_4);// GPIOPadConfigSet(GPIO_PORTL_BASE, GPIO_PIN_4,//GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD); } void scanline() {if (READ_L2 == GPIO_PIN_SET && READ_L1 == GPIO_PIN_SET && READ_M == GPIO_PIN_SET && READ_R1 == GPIO_PIN_SET && READ_R2 == GPIO_PIN_SET){brake();BUZZER_ON;delay_ms(500);BUZZER_OFF;delay_ms(500);brake();}else if (READ_L2 == GPIO_PIN_RESET && READ_L1 == GPIO_PIN_RESET && READ_M == GPIO_PIN_RESET && READ_R1 == GPIO_PIN_RESET && READ_R2 == GPIO_PIN_RESET){duty_set_all(MID_DUTY);car_front();}else if (READ_M == GPIO_PIN_SET){BUZZER_OFF;duty_set_all(MID_DUTY);car_front();//if(READ_L1 == GPIO_PIN_SET && READ_L2 == GPIO_PIN_SET){//BUZZER_ON;//car_left();//delay_ms(TURN_LEFT_TIME);//BUZZER_OFF;//duty_set_all(MID_DUTY);//car_front();//}//else if(READ_R1 == GPIO_PIN_SET && READ_R2 == GPIO_PIN_SET){//BUZZER_ON;//car_right();//delay_ms(TURN_RIGHT_TIME);//BUZZER_OFF;//duty_set_all(MID_DUTY);//car_front();//}}else{BUZZER_ON;delay_ms(100);BUZZER_OFF;if (READ_L1 == GPIO_PIN_SET){car_left();//if(READ_L2 == GPIO_PIN_SET){//car_right();//delay_ms(TURN_RIGHT_TIME - TURN_SMALL);//}delay_ms(TURN_SMALL);}else if (READ_L2 == GPIO_PIN_SET){car_left();//if(READ_L1 == GPIO_PIN_SET){//car_right();//delay_ms(TURN_RIGHT_TIME - TURN_BIG);//}delay_ms(TURN_BIG);}else if (READ_R1 == GPIO_PIN_SET){car_right();//if(READ_R2 == GPIO_PIN_SET){//car_left();//delay_ms(TURN_LEFT_TIME - TURN_SMALL);//}delay_ms(TURN_SMALL);}else if (READ_R2 == GPIO_PIN_SET){car_right();//if(READ_R1 == GPIO_PIN_SET){//car_left();//delay_ms(TURN_LEFT_TIME - TURN_BIG);//}delay_ms(TURN_BIG);}duty_set_all(MID_DUTY);} } int main(void) {// MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),120000000);MAP_SysCtlClockFreqSet((SYSCTL_OSC_INT | SYSCTL_USE_OSC), 16000000);SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);// Check if the peripheral access is enabled.GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); // LEDGPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, GPIO_PIN_1);GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);Delay_Init();GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0x0);GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0);key_init();gs_init();lpwm_init();rpwm_init();MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_0);MAP_PWMGenEnable(PWM0_BASE, PWM_GEN_1);brake();BUZZER_ON;delay_ms(500);BUZZER_OFF;while (1){if (scankeys() == 1)break;}BUZZER_ON;delay_ms(500);BUZZER_OFF;while (1) // Loop forever.{//scanline();if(READ_L1 == GPIO_PIN_SET){BUZZER_ON;delay_ms(80);BUZZER_OFF;delay_ms(80);}if(READ_L2 == GPIO_PIN_SET){BUZZER_ON;delay_ms(80);BUZZER_OFF;delay_ms(80);BUZZER_ON;delay_ms(80);BUZZER_OFF;delay_ms(80);}if(READ_M == GPIO_PIN_SET){BUZZER_ON;delay_ms(80);BUZZER_OFF;delay_ms(80);BUZZER_ON;delay_ms(80);BUZZER_OFF;delay_ms(80);BUZZER_ON;delay_ms(80);BUZZER_OFF;delay_ms(80);}if(READ_R2 == GPIO_PIN_SET){BUZZER_ON;delay_ms(80);BUZZER_OFF;delay_ms(80);BUZZER_ON;delay_ms(80);BUZZER_OFF;delay_ms(80);}if(READ_R1 == GPIO_PIN_SET){BUZZER_ON;delay_ms(80);BUZZER_OFF;delay_ms(80);}delay_ms(200);} }
Yale Li:
您好,您是自己创建的工程并添加的代码吗?我建议您在例程的基础上修改。您下载SIMPLELINK-MSP432E4-SDK并在默认安装路径安装以后,会在C:\ti\simplelink_msp432e4_sdk_4_20_00_12\examples\nortos\MSP_EXP432E401Y\driverlib找到相关例程。