Other Parts Discussed in Thread: CC2530
Hi
My project runs normally in the Debug mode
but when stop the Debug mode and reset, it doesn't work
What is the problem
thanks in advance
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Other Parts Discussed in Thread: CC2530
Hi
My project runs normally in the Debug mode
but when stop the Debug mode and reset, it doesn't work
What is the problem
thanks in advance
thank you very much Igor
I tried the methods in the post but it still doesn't work..
Problem is
in the debug mode I run it step by step then I see the value change in the register ,
if I click 'go',nothing change, looks like the program just 'jump through' some functions
I am confused.....
Hi Li,
Is it "skips" variables or is it more "jumps through" whole functions?
The IAR does optimization to the code, so sometimes it "skips" the
lines in your code, where actually it jumps to procedure in assembly
level, and executes it there.
Very uncomfortable to debug, however it works. In case you see that
IAR jumps over lines in C code and the functionality you designed
still works, this an accepted behaviour.
If it is not the case, is the behaviour you see while debugging is the
same behaviour you see when your device unplugged.
Br,
Igor
Thank you Igor
It is more like "skips" variables,because programm goes into the function and stops at the breakpoint I set
But the variables only change when I run the programm step by step.....otherwise nothing changes
here is the code
I use the Sensor Demo
in the original DemoSensor.c
static void sendReport(void)
{......
// Read and report temperature value
pData[SENSOR_TEMP_OFFSET] = readTemp();
......
zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, SENSOR_REPORT_LENGTH, pData, 0, txOptions, 0 );
}
I want to send a data from acceleration sensor which connect the board with SPI
so here is my code
static void sendReport(void)
{......
// Read and report Acc value
pData[X_L] = Read_From_Register(0xA8);
......
zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, SENSOR_REPORT_LENGTH, pData, 0, txOptions, 0 );
}
//**********************Read_From_Register******************************************//
static int8 Read_From_Register(int8 register_address )
{
static int8 accleration;
#if defined (HAL_MCU_CC2530)
SPI_INIT( );
SSN = LOW;
// read from register
U1DBUF = register_address;
while (!U1TX_BYTE);
U1TX_BYTE = 0;
U1DBUF = 0x00;
while (!U1TX_BYTE);
accleration = U1DBUF;// read the data from Sensor
U1TX_BYTE = 0;
SSN = HIGH;
return(accleration);
#else
return 0;
#endif
}
//**********SPI_INIT *********************
static void SPI_INIT(void)
{
//*********USART1,Alternative 2****************
PERCFG |= 0x02; // PERCFG.U1CFG = 1
P1SEL |= 0xE0; // P1_7, P1_6, and P1_5 are peripherals
P1SEL &= ~0x10; // P1_4 is GPIO (SSN)
P1DIR |= 0x10; // SSN is set as output
// init_Baudrate
//********** Set baud rate to 2400*************
U1BAUD = 0x3B; // BAUD_M = 59
U1GCR &= 0xE0;
U1GCR |= 0x06; // BAUD_E = 6
// SPI Master Mode
U1CSR &= ~0xA0;
// Configure phase, polarity, and bit order
U1GCR |= 0xC0; // CPOL = 1 CPHA = 1
U1GCR |= 0x20; // ORDER = 1
//********Sensor Init************************
SSN = LOW;
//Write C7 to CTRL_REG1
U1DBUF = 0x20;
while (!U1TX_BYTE);
U1TX_BYTE = 0;
U1DBUF = 0xC7;
while (!U1TX_BYTE);
U1TX_BYTE = 0;
SSN = HIGH;
}
So in the debug mode the program goes into the Read_From_Register( ) Function, the U1DBUF and accleration value change like I expect. at this time I stop the debug mode it runs normally, But if I just download the program into chip without debug or I reset the chip, It doesn't work. So every time I have to start the system by running in the debug mode first and I can not reset the system......
thank you
I didn't see mention of target and stack, so I will use CC2530EB and ZStack 2.5.0. Look at an example of how to be a SPI master in hal_lcd.c:
/* clear the received and transmit byte status, write tx data to buffer, wait till transmit done */
#define LCD_SPI_TX(x) { U1CSR &= ~(BV(2) | BV(1)); U1DBUF = x; while( !(U1CSR & BV(1)) ); }
#define LCD_SPI_WAIT_RXRDY() { while(!(U1CSR & BV(1))); }
You will see that your error is to clear the TX_BYTE bit after writing the DBUF and so your first "while (!U1TX_BYTE);" doesn't wait for anything and the code races ahead and the second byte clobbers the first and the slave receives a mangled garbage byte. But when stepping, the first byte has time to get out before you step to writing the second one. Also, by writing zero to the register you are clobbering the RE bit 6 - how do you ever receive anything after that, even when running from debugger?
thank you very very much Dirty Harry
I rewrite the SPI part according to the following code
#define LCD_SPI_TX(x) { U1CSR &= ~(BV(2) | BV(1)); U1DBUF = x; while( !(U1CSR & BV(1)) ); }
#define LCD_SPI_WAIT_RXRDY() { while(!(U1CSR & BV(1))); }
and now it works
Thank you so much