为什么EFM32 SPI手动CS使TX,CLK问题不起作用

问题描述

我将EFM32LG USART0 LOC0用于我的控制器图,如以下数据表所示。 我已经在github中基于series0 SPI MASTER示例构建了下面的代码。 但是,当我尝试将autoCSenable = false设置为手动执行chipselect时,则我没有来自端口E 12的时钟,并且没有端口E引脚10中发送的任何数据。 我得到电压值,该值在GPIO中认设置。 我哪里做错了? 谢谢。

enter image description here

enter image description here

/**************************************************************************//**
 * @main_series0_G_GG_WG_LG
 * @brief Demonstrates USART1 as SPI master.
 * @version 0.0.1
 ******************************************************************************
 * @section License
 * <b>copyright 2018 Silicon Labs,Inc. http://www.silabs.com</b>
 *******************************************************************************
 *
 * This file is licensed under the Silabs License Agreement. See the file
 * "Silabs_License_Agreement.txt" for details. Before using this software for
 * any purpose,you must agree to the terms of that agreement.
 *
 ******************************************************************************/

#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "em_usart.h"

#define TX_BUFFER_SIZE   4
#define RX_BUFFER_SIZE   TX_BUFFER_SIZE
volatile uint32_t msTicks; /* counts 1ms timeTicks */

void Delay(uint32_t dlyTicks);
void SysTick_Handler(void)
{
  msTicks++;       /* increment counter necessary in Delay()*/
}
void Delay(uint32_t dlyTicks)
{
  uint32_t curTicks;

  curTicks = msTicks;
  while ((msTicks - curTicks) < dlyTicks) ;
}

uint8_t TxBuffer[TX_BUFFER_SIZE] = {0b00000011,0b00000111,0b11111111,0b11110000};
uint32_t TxBufferIndex = 0;

uint8_t RxBuffer[RX_BUFFER_SIZE] = {0};
uint32_t RxBufferIndex = 0;


int main(void)
{
  // Initialize chip
  CHIP_Init();

  CMU_ClockEnable(cmuClock_GPIO,true);
  CMU_ClockEnable(cmuClock_USART0,true);
  GPIO_PinModeSet(gpioPortE,12,gpioModePushPull,0); // US1_CLK is push pull
    GPIO_PinModeSet(gpioPortA,2,1); // US1_CS is push pull
    GPIO_PinModeSet(gpioPortE,10,0); // US1_TX (MOSI) is push pull
    GPIO_PinModeSet(gpioPortE,11,gpioModeInput,1);    // US1_RX (MISO) is input
    GPIO_PinModeSet(gpioPortA,3,0);    // LDAC

  ///////////////////////////////////////////////////////
  // Start with default config,then modify as necessary
   USART_InitSync_TypeDef config = USART_INITSYNC_DEFAULT;
   config.master       = true;            // master mode
   config.baudrate     = 1000000;         // CLK freq is 1 MHz
   config.autoCsEnable = false;            // CS pin controlled by hardware,not firmware
   config.clockMode    = usartClockMode0; // clock idle low,sample on rising/first edge
   config.msbf         = true;            // send MSB first
   config.enable       = usartdisable;    // making sure to keep USART disabled until we've set everything up
   USART_InitSync(USART0,&config);
   USART0->ROUTE = USART_ROUTE_CLKPEN | USART_ROUTE_CSPEN | USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC0;
   ///////////////////////////////////////////

    TxBufferIndex = 0;
  while(1)
  {
      Delay(1000);
        GPIO_PinOutClear(gpioPortA,2);
      USART_Tx(USART0,TxBuffer[TxBufferIndex++]);
      GPIO_PinOutSet(gpioPortA,2);
      // Stop sending once we've gone through the whole TxBuffer
      if (TxBufferIndex == TX_BUFFER_SIZE)
      {
        TxBufferIndex = 0;
      }

  }
  }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)