Hello,
I recently started coding my CC2538 (connected to SmartRF06 EB) to establish a SPI connection to a MEMS-based accelerometer in IAR, but I can't get the code from the peripheral driver library to work. It compiles fine, without any warnings or errors, but when I debug it a weird loop is present in one of the driver functions.
Here's my code:
//driver library
#include "stdio.h"
#include "ssi.h"
#include "sys_ctrl.h"
#include "stdint.h"
#include "hw_memmap.h"
#include "gpio.h"
#include "ioc.h"
#include "hw_ioc.h"
#include "iocc2538.h"
#include "hw_gpio.h"
#include "debug.h"
#define PIN_SSI_CLK GPIO_PIN_2
#define PIN_SSI_FSS GPIO_PIN_3
#define PIN_SSI_RX GPIO_PIN_4 //MISO
#define PIN_SSI_TX GPIO_PIN_5 //MOSI
#define GPIO_SSI_BASE GPIO_A_BASE
void initConsole (void);
void main(void)
{
//initilization
initConsole();
//get data from accelerometer}
void initConsole (void)
{
//set clocks
SysCtrlClockSet (false, false, SYS_CTRL_SYSDIV_32MHZ);
SysCtrlIOClockSet(SYS_CTRL_SYSDIV_32MHZ);
//initialize GPIO pins as SSI}
The problem occurs in the SysCtrlClockSet function whose definition is below. Somehow the program loops between the two highlighted lines even though there isn't a loop present that could cause it.
void
SysCtrlClockSet(bool bExternalOsc32k, bool bInternalOsc,
uint32_t ui32SysDiv)
{
uint32_t ui32STA;
uint32_t ui32Reg;
uint32_t ui32TimeoutVal;
uint32_t ui32Osc;
// check input parameters
ASSERT((ui32SysDiv == SYS_CTRL_SYSDIV_32MHZ ||
ui32SysDiv == SYS_CTRL_SYSDIV_16MHZ ||
ui32SysDiv == SYS_CTRL_SYSDIV_8MHZ ||
ui32SysDiv == SYS_CTRL_SYSDIV_4MHZ ||
ui32SysDiv == SYS_CTRL_SYSDIV_2MHZ ||
ui32SysDiv == SYS_CTRL_SYSDIV_1MHZ ||
ui32SysDiv == SYS_CTRL_SYSDIV_500KHZ ||
ui32SysDiv == SYS_CTRL_SYSDIV_250KHZ) &&
!((ui32SysDiv == SYS_CTRL_SYSDIV_32MHZ) && bInternalOsc));
//
// Enable AMP detect to make sure XOSC starts correctly
//
if(!bInternalOsc)
{
ui32Reg = HWREG(SYS_CTRL_CLOCK_CTRL) | SYS_CTRL_CLOCK_CTRL_AMP_DET;
HWREG(SYS_CTRL_CLOCK_CTRL) = ui32Reg;
}
//
// Set 32kHz clock, Osc and SysDiv
//
ui32Reg = HWREG(SYS_CTRL_CLOCK_CTRL);
ui32Reg &= ~(SYS_CTRL_CLOCK_CTRL_OSC32K | SYS_CTRL_CLOCK_CTRL_OSC |
SYS_CTRL_CLOCK_CTRL_SYS_DIV_M);
if(!bExternalOsc32k)
{
ui32Reg |= SYS_CTRL_CLOCK_CTRL_OSC32K;
}
ui32Osc = bInternalOsc ? SYS_CTRL_CLOCK_CTRL_OSC : 0;
ui32Reg |= ui32Osc;
ui32Reg |= ui32SysDiv;
HWREG(SYS_CTRL_CLOCK_CTRL) = ui32Reg;
//
// Note: This wait loop could potentially be removed, if caution
// is taken in code running after this call.
//
// If we have changed Osc settings, wait until change happens
//
ui32STA = HWREG(SYS_CTRL_CLOCK_STA);
ui32TimeoutVal = 0;
while((ui32Osc != (ui32STA & SYS_CTRL_CLOCK_CTRL_OSC)) &&
(ui32TimeoutVal < SYS_CTRL_TIMEOUT))
{
SysCtrlDelay(16);
ui32STA = HWREG(SYS_CTRL_CLOCK_STA);
ui32TimeoutVal++;
}
ASSERT(ui32TimeoutVal < SYS_CTRL_TIMEOUT);
}
Here is the log when I run it, is the Set SYS_CTRL:EMUOVR Register a problem? I couldn't find anything in the documentation to sovle it, but apparently it mean its suck in sleep mode?
Wed Jun 03, 2015 09:43:09: Loaded macro file: C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.0\arm\config\debugger\TexasInstruments\
CC2538.dmac
Wed Jun 03, 2015 09:43:10: Connecting to TI XDS100 (Probe no: 06EB12100B24)
Wed Jun 03, 2015 09:43:11: Initial reset was performed
Wed Jun 03, 2015 09:43:11: TI XDS100/200/ICDI ARM, device revision: 0x00000001, big endian: false, cache: false, board revision: 0x00000000, driver revision:
0x0B020200
Wed Jun 03, 2015 09:43:12: 2654 bytes downloaded (15.07 Kbytes/sec)
Wed Jun 03, 2015 09:43:12: Loaded debugee: C:\Users\Low Frequency Lab\Desktop\Brendon\IAR\Accelerometer 2.0\Debug\Exe\c.out
Wed Jun 03, 2015 09:43:12: Target reset
Wed Jun 03, 2015 09:43:12: Hardware reset with delay 0 ms was performed
Wed Jun 03, 2015 09:43:12: Set SYS_CTRL:EMUOVR Register
Also, when I go to project>download the option to erase memory is not available even though I can do so with other programs, so I don't think the program is being download properly. The project is configured for the CC2538SF53 and the XDS100v3 emulator.
Any help would be greatly appreciated, thanks.