Cortex-M/EFM322013. 4. 30. 22:30

EFM32G210 EVM - SPI 테스트

EFM32G210 EVM - SPI 테스트



EFM32의 SPI최대 클럭 속도는 14Mhz 까지 동작한다. (최대 peripheral clock이 28Mhz 이므로.. )

- SPI master mode, peripheral clock rate/2



EFM32G210 EVM 보드에서 SPI핀을 USART1에 할당하였다.




EFM32 SPI 블록도



EFM32 SPI 초기화 함수

void SPI0_Init(void)

{

    CMU_ClockEnable(cmuClock_USART1, true);    

    

    USART_TypeDef *SPI0;

    SPI0 = USART1;

    

    /* Setting baudrate */

    SPI0->CLKDIV = 128 * (SPI_PERCLK_FREQUENCY / SPI_BAUDRATE - 2);


    /* Configure SPI */

    /* Using synchronous (SPI) mode*/

    SPI0->CTRL = USART_CTRL_SYNC;

    /* Clearing old transfers/receptions, and disabling interrupts */

    SPI0->CMD = USART_CMD_CLEARRX | USART_CMD_CLEARTX;

    SPI0->IEN = 0;


    /* Enabling pins and setting location */

    SPI0->ROUTE = USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_CLKPEN | (0 << 8);

    /* Set GPIO config to slave */

    GPIO_Mode_TypeDef gpioModeMosi = gpioModeInput;

    GPIO_Mode_TypeDef gpioModeMiso = gpioModePushPull;

    GPIO_Mode_TypeDef gpioModeClk  = gpioModeInput;   

 

    /* Enabling Master, TX and RX */

    SPI0->CMD   = USART_CMD_MASTEREN | USART_CMD_TXEN | USART_CMD_RXEN;

    SPI0->CTRL |= (USART_CTRL_MSBF);


    /* Set GPIO config to master */

    gpioModeMosi = gpioModePushPull;

    gpioModeMiso = gpioModeInput;

    gpioModeClk  = gpioModePushPull;


    GPIO_PinModeSet(gpioPortC, 0, gpioModeMosi, 0);  /* MOSI */

    GPIO_PinModeSet(gpioPortC, 1, gpioModeMiso, 0);  /* MISO */

    GPIO_PinModeSet(gpioPortB, 7, gpioModeClk,  0);  /* Clock */    

}



EFM32 SPI Read, Write 함수

unsigned char SPI0_WriteReadByte(unsigned char Data)

{

    USART_TypeDef *SPI0 = USART1;

    while (!(SPI0->STATUS & USART_STATUS_TXBL)) ;

    SPI0->TXDATA = Data;


    while (!(SPI0->STATUS & USART_STATUS_RXDATAV)) ;

    return (SPI0->RXDATA);    

}




Posted by nexp

댓글을 달아 주세요