Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] EFM32 SPI manual CS makes TX ,CLK problem not functioning

Status
Not open for further replies.

yefj

Advanced Member level 5
Advanced Member level 5
Joined
Sep 12, 2019
Messages
1,505
Helped
1
Reputation
2
Reaction score
5
Trophy points
38
Activity points
9,114
Hello,I am using EFM32LG USART0 LOC0 for my Controller diagram as shown in the data sheet bellow. I have built the code bellow based on the series0 SPI MASTER example in github. But when i try to put autoCSenable =false in order to manualy doing chipselect then i dont have any clock from PORT E 12 and I dont have any data sending in port E pin 10. I get Voltage values which where set by default in GPIO.
Where did i go wrong?
Thanks.
Code:
/**************************************************************************//**
 * @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, 1); // US1_CLK is push pull
    GPIO_PinModeSet(gpioPortA, 2, gpioModePushPull, 1); // US1_CS is push pull
    GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 0); // US1_TX (MOSI) is push pull
    GPIO_PinModeSet(gpioPortE, 11, gpioModeInput, 1);    // US1_RX (MISO) is input
    GPIO_PinModeSet(gpioPortA, 3, gpioModePushPull, 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

   USART_InitSync(USART0, &config);
   USART0->ROUTE = USART_ROUTE_CLKPEN | USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC0;
   ///////////////////////////////////////////
   USART_Enable(USART0, usartEnable);
    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;
      }

  }
  }
1598530834588.png
 

Attachments

  • 1598530861821.png
    1598530861821.png
    282.4 KB · Views: 179
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top