五.microchip 代理贝能的sam d51(LQFP100PIN)与LAN9253 电机控制开发板使用总结(3)

五.microchip 代理贝能的sam d51(LQFP100PIN)与LAN9253 电机控制开发板使用总结(3)

3.4 板子相关外设配置

3.4.1 板子MCU硬件 的LAN9253连接接口

pin num pin id cus_name func mode dir latch push up push down dir str
1 PA00 GPIO_PA0_D0 GPIO IN Y NORMAL
2 PA01 GPIO_PA1 GPIO IN Y NORMAL
7 PA02 GPIO_PA2 GPIO IN Y NORMAL
8 PA03 GPIO_PA3 GPIO IN Y NORMAL
17 PA04 GPIO_PA4 GPIO IN Y NORMAL
18 PA05 GPIO_PA5 GPIO IN Y NORMAL
19 PA06 GPIO_PA6 GPIO IN Y NORMAL
20 PA07 GPIO_PA7_D7 GPIO IN Y NORMAL
26 PA08 GPIO_PA8_SPI_DATA GPIO IN/out Y NORMAL
32 PA10 GPIO_PB10_SPI_CLK GPIO IN/out Y NORMAL
33 PB11 GPIO_PB11_SPI_CS GPIO IN/out Y NORMAL
46 PA12 GPIO_PA12_D12 GPIO IN Y NORMAL
47 PA13 GPIO_PA13 GPIO IN Y NORMAL
48 PA14 GPIO_PA14 GPIO IN Y NORMAL
49 PA15 GPIO_PA15_D15 GPIO IN Y NORMA
52 PA16 GPIO_PA16_D8 GPIO IN Y NORMAL
53 PA17 GPIO_PA17 GPIO IN Y NORMAL
54 PA18 GPIO_PA18 GPIO IN Y NORMAL
55 PA19 GPIO_PA19_D11 GPIO IN Y NORMA
64 PB16 GPIO_PB16_RD GPIO OUT Y NORMA
65 PB17 GPIO_PB17_WR GPIO OUT Y NORMA
66 PB18 GPIO_PB18_CS GPIO OUT Y NORMA
78 PB22 GPIO_PB22_A1 GPIO OUT Y NORMA
79 PB23 GPIO_PB23_A2 GPIO OUT Y NORMA
80 PB24 GPIO_PB24_A3 GPIO OUT Y NORMA
21 PB25 GPIO_PB25_A4 GPIO OUT Y NORMA

3.4.2 MCU TCC–PWM 电机控制

五.microchip 代理贝能的sam d51(LQFP100PIN)与LAN9253 电机控制开发板使用总结(3)_第1张图片

PIN40–PC10–PWM0H

PIN41–PC11–PWM0L

PIN42–PC12–PWM1H

PIN43–PC13–PWM1L

PIN44–PC14–PWM2H

PIN45–PC15–PWM2L
五.microchip 代理贝能的sam d51(LQFP100PIN)与LAN9253 电机控制开发板使用总结(3)_第2张图片

Timer/Counter for Control applications (TCC) peripheral
五.microchip 代理贝能的sam d51(LQFP100PIN)与LAN9253 电机控制开发板使用总结(3)_第3张图片

3.4.2.1 应用调用例子

        /* Register callback function for period event */
    TCC0_PWMCallbackRegister(TCC_PeriodEventHandler, (uintptr_t)NULL);
    
    /* Read the period */
    period = TCC0_PWM24bitPeriodGet();
    
    /* Start PWM*/
    TCC0_PWMStart();
/***************************************
 * Check PWM outputs on pins
 * Channel 0 PWMH - PC04
 * Channel 0 PWML - PD11
 * Channel 1 PWMH - PD08
 * Channel 1 PWML - PB17
 * Channel 2 PWMH - PB14
 * Channel 2 PWML - PC22
***************************************/

/* Duty cycle increment value */
#define DUTY_INCREMENT (10U)

/* Save PWM period */
uint32_t period;

/* This function is called after TCC period event */
void TCC_PeriodEventHandler(uint32_t status, uintptr_t context)
{
    /* duty cycle values */
    static uint32_t duty0 = 0U;
    static uint32_t duty1 = 800U;
    static uint32_t duty2 = 1600U;

    TCC0_PWM24bitDutySet(TCC0_CHANNEL0, duty0);
    TCC0_PWM24bitDutySet(TCC0_CHANNEL1, duty1);
    TCC0_PWM24bitDutySet(TCC0_CHANNEL2, duty2);
    
    /* Increment duty cycle values */
    duty0 += DUTY_INCREMENT;
    duty1 += DUTY_INCREMENT;
    duty2 += DUTY_INCREMENT;
    
    if (duty0 > period)
        duty0 = 0U;
    if (duty1 > period)
        duty1 = 0U;
    if (duty2 > period)
        duty2 = 0U;

}

3.4.3 MCU ADC–IA/IB/IC

五.microchip 代理贝能的sam d51(LQFP100PIN)与LAN9253 电机控制开发板使用总结(3)_第4张图片

15 PB08 IA

16 PB09 IB

97 PB00 IC

3.4.4 MCU GPIO–网卡指示灯

74 PA24 RJLED2

75 PA25 RJLED1
五.microchip 代理贝能的sam d51(LQFP100PIN)与LAN9253 电机控制开发板使用总结(3)_第5张图片

3.4.4.1 应用调用例子

/*** Macros for LED pin ***/
#define RJLED2_Set()               (PORT_REGS->GROUP[0].PORT_OUTSET = ((uint32_t)1U << 24U))
#define RJLED2_Clear()             (PORT_REGS->GROUP[0].PORT_OUTCLR = ((uint32_t)1U << 24U))
#define RJLED2_Toggle()            (PORT_REGS->GROUP[0].PORT_OUTTGL = ((uint32_t)1U << 24U))
#define RJLED2_OutputEnable()      (PORT_REGS->GROUP[0].PORT_DIRSET = ((uint32_t)1U << 24U))
#define RJLED2_InputEnable()       (PORT_REGS->GROUP[0].PORT_DIRCLR = ((uint32_t)1U << 24U))
#define RJLED2_Get()               (((PORT_REGS->GROUP[0].PORT_IN >> 24U)) & 0x01U)
#define RJLED2_PIN                  PORT_PIN_PA24

#define RJLED1Set()               (PORT_REGS->GROUP[0].PORT_OUTSET = ((uint32_t)1U << 25U))
#define RJLED1_Clear()             (PORT_REGS->GROUP[0].PORT_OUTCLR = ((uint32_t)1U << 25U))
#define RJLED1_Toggle()            (PORT_REGS->GROUP[0].PORT_OUTTGL = ((uint32_t)1U << 25U))
#define RJLED1_OutputEnable()      (PORT_REGS->GROUP[0].PORT_DIRSET = ((uint32_t)1U << 25U))
#define RJLED1_InputEnable()       (PORT_REGS->GROUP[0].PORT_DIRCLR = ((uint32_t)1U << 25U))
#define RJLED1_Get()               (((PORT_REGS->GROUP[0].PORT_IN >> 25U)) & 0x01U)
#define RJLED1_PIN                  PORT_PIN_PA25

3.4.5 MCU EIC–KEY S1

按键中断

69 PB21 KEY1
五.microchip 代理贝能的sam d51(LQFP100PIN)与LAN9253 电机控制开发板使用总结(3)_第6张图片

默认1,按下按键0

3.4.5.1 应用调用例子

   EIC_CallbackRegister(EIC_PIN_5,EIC_User_Handler, 0);
static void EIC_User_Handler(uintptr_t context)
{
//    LED_Toggle();
    SERCOM0_USART_Write("EIC is ok!", sizeof"EIC is ok!");
}

3.4.5.2 板子没有复位按键,使用另外按键进行复位

static void EIC_User_Handler(uintptr_t context)
{
//    LED_Toggle();
    SERCOM0_USART_Write("EIC is ok!", sizeof"EIC is ok!");
    NVIC_SystemReset();
}

3.4.6 MCU key EIC -->evsys–>led tog

按键按下EIC中断,在中断处理函数中进行控制LED TOG.

那么是否有更好或者其他的方式呢?

按键按下,EIC输出到ev sys,ev sys直接进行控制LED TOG,不需要CPU参与。

当然也可以实现按键按下,产生EIC中断输出,在中断处理函数中进行控制LED TOG.

也同时可以EIC事件输出,ev sys直接进行控制LED TOG,不需要CPU参与。

https://www.microchip.com/forums/m1173949.aspx

你可能感兴趣的:(单片机,stm32,嵌入式硬件)