free性丰满hd毛多多,久久综合给合久久狠狠狠97色69 ,欧美成人乱码一区二区三区,国产美女久久久亚洲综合,7777久久亚洲中文字幕

0
問答首頁 最新問題 熱門問題 等待回答標(biāo)簽廣場
我要提問

efm32 硬件SPI

void SPI_setup(uint8_t spiNumber, uint8_t location, bool master)
{
??USART_TypeDef *spi;
??/* Determining USART */
??switch (spiNumber)
??{
??case 0:
? ? spi = USART0;
? ? break;
??case 1:
? ? spi = USART1;
? ? break;
??case 2:
? ?// spi = USART2;
? ? break;
??default:
? ? return;
??}
? ? //USART_Reset(spi);
??/* Setting baudrate */
??spi->CLKDIV = 128 * (SPI_PERCLK_FREQUENCY / SPI_BAUDRATE - 2);
??
??/* Configure SPI */
??/* Using synchronous (SPI) mode*/
??//spi->CTRL = USART_CTRL_SYNC;//|USART_CTRL_CLKPHA;
? ?spi->CTRL = USART_CTRL_SYNC ;//|USART_CTRL_CLKPHA;//|USART_CTRL_CLKPOL ;
??//spi->FRAME|=USART_FRAME_DATABITS_EIGHT;
??/* Clearing old transfers/receptions, and disabling interrupts */
??spi->CMD = USART_CMD_CLEARRX | USART_CMD_CLEARTX;
??spi->IEN = 0;
??/* Enabling pins and setting location */
??spi->ROUTE = USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_CLKPEN | USART_ROUTE_CSPEN | (location << 8);
??
??/* Set GPIO config to slave */

??
??/* Set to master and to control the CS line */
??if (master)
??{
? ? /* Enabling Master, TX and RX */
? ? spi->CMD? ?= USART_CMD_MASTEREN | USART_CMD_TXEN | USART_CMD_RXEN;
? ? spi->CTRL |= USART_CTRL_AUTOCS;
? ?? ?/* 數(shù)據(jù)傳輸高位在前 */
? ???spi->CTRL |=USART_CTRL_MSBF;
? ?
? ? /* Set GPIO config to master */
? ? gpioModeMosi = gpioModePushPull;
? ? gpioModeMiso = gpioModePushPull;
? ? gpioModeCs? ?= gpioModePushPull;
? ? gpioModeClk??= gpioModePushPull;
??}
??else
??{
? ? /* Enabling TX and RX */
? ? spi->CMD = USART_CMD_TXEN | USART_CMD_RXEN;
? ???/* Set GPIO config to slave */
? ? gpioModeMosi = gpioModeInput;
? ? gpioModeMiso = gpioModePushPull;
? ? gpioModeCs? ?= gpioModeInput;
? ? gpioModeClk??= gpioModeInput;
??}
??/* Clear previous interrupts */
??spi->IFC = _USART_IFC_MASK;
??/* IO configuration */
??switch(spiNumber)
??{
? ? case 0: switch(location)
? ?? ?? ?? ?{
? ?? ?? ?? ???case 0: /* IO configuration (USART 0, Location #0) */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortE, 10, gpioModeMosi, 0); /* MOSI */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortE, 11, gpioModeMiso, 0); /* MISO */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortE, 13, gpioModeCs,? ?0); /* CS */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortE, 12, gpioModeClk,??0); /* Clock */
? ?? ?? ?? ?? ?? ?? ? break;
? ?? ?? ?? ???case 1: /* IO configuration (USART 0, Location #1) */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortE, 7, gpioModeMosi, 0);??/* MOSI */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortE, 6, gpioModeMiso, 0);??/* MISO */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortE, 4, gpioModeCs,? ?0);??/* CS */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortE, 5, gpioModeClk,??0);??/* Clock */
? ?? ?? ?? ?? ?? ?? ? break;
? ?? ?? ?? ???case 2: /* IO configuration (USART 0, Location #2) */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortC, 11, gpioModeMosi, 0); /* MOSI */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortC, 10, gpioModeMiso, 0); /* MISO */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortC,??8, gpioModeCs,? ?0); /* CS */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortC,??9, gpioModeClk,??0); /* Clock */
? ?? ?? ?? ?? ?? ?? ? break;
? ?? ?? ?? ?default: break;
? ?? ?? ?? ?}
? ?? ?? ?? ?break;
? ? case 1: switch(location)
? ?? ?? ?? ?{
? ?? ?? ?? ???case 0: /* IO configuration (USART 1, Location #0) */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortC, 0, gpioModeMosi, 0);??/* MOSI */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortC, 1, gpioModeMiso, 0);??/* MISO */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortB, 8, gpioModeCs,? ?0);??/* CS */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortB, 7, gpioModeClk,??0);??/* Clock */
? ?? ?? ?? ?? ?? ?? ? break;
? ?? ?? ?? ???case 1: /* IO configuration (USART 1, Location #1) */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortD, 0, gpioModeMosi, 0);??/* MOSI */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortD, 1, gpioModeMiso, 0);??/* MISO */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortD, 3, gpioModeCs,? ?0);??/* CS */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortD, 2, gpioModeClk,??0);??/* Clock */
? ?? ?? ?? ?? ?? ?? ? break;? ?? ?? ?? ???
? ?? ?? ?? ?default: break;
? ?? ?? ?? ?}
? ?? ?? ?? ?break;
? ? case 2: switch(location)
? ?? ?? ?? ?{
? ?? ?? ?? ???case 0: /* IO configuration (USART 2, Location #0) */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortC, 2, gpioModeMosi, 0);??/* MOSI */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortC, 3, gpioModeMiso, 0);??/* MISO */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortC, 5, gpioModeCs,? ?0);??/* CS */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortC, 4, gpioModeClk,??0);??/* Clock */
? ?? ?? ?? ?? ?? ?? ? break;
? ?? ?? ?? ???case 1: /* IO configuration (USART 2, Location #1) */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortB, 3, gpioModeMosi, 0);??/* MOSI */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortB, 4, gpioModeMiso, 0);??/* MISO */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortB, 6, gpioModeCs,? ?0);??/* CS */
? ?? ?? ?? ?? ?? ?? ? GPIO_PinModeSet(gpioPortB, 5, gpioModeClk,??0);??/* Clock */
? ?? ?? ?? ?? ?? ?? ? break;? ?? ?? ?? ???
? ?? ?? ?? ?default: break;
? ?? ?? ?? ?}
? ?? ?? ?? ?break;
? ? default: break;??
??}
}
我這里對其初始化,可是在示波器看到cs輸出波形不對,請大家?guī)兔鉀Q一下
提問者:60user175 地點(diǎn):- 瀏覽次數(shù):9844 提問時(shí)間:05-19 20:04
我有更好的答案
提 交
撰寫答案
提 交
1 / 3
1 / 3