cancel
Showing results for 
Search instead for 
Did you mean: 

start STM32W108 module zigbee

hibiscusblau
Associate II
Posted on March 01, 2013 at 13:37

Hi, 

I'm new in that technology and this microcontroller. 

I want to program my zigbee module in order to send me a ''hello world'' message through UART. 

I have connect my module with STM32W108 ucontroller with a dsPIC. My dsPIC have 2 uarts, UART1 I've configured to comunicate to my Pc and UART2 to comunicate with Zigbee. 

I've programmed the following code in my dspic:

void ZigProgram(){

char CaracterRebut;

if (nBOOTMODE == 0){ //estem en mode bootloader, de programaci�. 

sprintf(sTxt, ''0x7F''); //commanda d'iniciaci�

putsUART2((unsigned int *)sTxt);

while (BusyUART2()); // M'espero mentres es transmet

while (UartTincDada2 () == 0); //mentre no rebo res m'espero

// si surto, �s perqu� tinc dades

UartPintaDada2 ();

CaracterRebut = UartReturnBuf_Rx2 ();

if (CaracterRebut == 0x79){

sprintf(sTxt, ''\r\n CaracterRebut �s 0x79 \r\n'');

putsUART1((unsigned int *)sTxt);

//ACK ok. Puc comen�ar a demanar coses

sprintf(sTxt, ''0x00''); //command Get. 

putsUART2((unsigned int *)sTxt);

while (UartTincDada2 () == 0); //mentre no rebo res m'espero

// si surto, �s perqu� tinc dades

//CaracterRebut = UartReturnBuf_Rx2 ();

UartPintaDada2 ();

}else{

//error. NACK?

sprintf(sTxt, ''\r\n CaracterRebut �s 0x%x \r\n'', CaracterRebut);

putsUART1((unsigned int *)sTxt);

}

nBOOTMODE = ON; //el torno a pujar

}else{

sprintf(sTxt, ''\r\n nBOOTMODe val on \r\n'');

putsUART1((unsigned int *)sTxt);

}

}

In order to program it. So, I initialize with nBOOTMODE pin (from dsp) in '0'. My UART2 is configurated with a baudrate 115200, even parity, 8 bits, 1 stop bit. 

Always I recieved a pulse train from Zigbee. What it means? 

Does anybody know what I do wrong? I know this is complicated, but does anybody have a started C code to program it?

Thanks in advance!

#one-step-at-a-time #example-usart #zigbee-stm32w108-usart-start #walk-before-you-run
9 REPLIES 9
Posted on March 01, 2013 at 15:54

sprintf(sTxt, ''0x7F''); //commanda d'iniciació

Not ASCII, you need to send an 8-bit value, 0x7F or 127
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hibiscusblau
Associate II
Posted on March 01, 2013 at 18:37

Thanks, clive1.

But I've changed it and the problem is going on..

Where I can find a simple code/example in order to program it in C language which comunicates via usart? 

Thanks,

Posted on March 01, 2013 at 18:48

The Flash Loader Demonstrator source code? Or one of the other open source equivalents?

The protocol is reasonably well documented, I wrote a loader from scratch.

I would suggest you experiment with a terminal program that can send hex codes (RealTerm?), and observe how the chip reacts prior to attempting to automate the solution.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hibiscusblau
Associate II
Posted on March 04, 2013 at 13:30

Thanks a lot clive1, 

I'm been carrying out yours advices. 

In order to do it, I first try with my evaluation board, which I've solded three wires in the pads 20(tx), 21(rx) and 28(gnd) which I've connected to a bord with UB232 module USB. I've connected pin 20 from STM32 to pin 8 of UB232R, pin 21 from STM32 to pin 7 of UB232R, and pin 28 from STM32 (gnd) to pin 1 of UB232R. 

I check my signals into oscilloscope, and I see a continue 1.82v and 1.59v in each channel. I don't know why, because I think I should see 0's or 1's. What is it happen?

Untill now, I've never worked with Realterm, but I suppose I have to configurate USB protocol (baudrate, parity, stop bit, etc..), in Display tap ''Display As: Hex'' and in Send tap write what hex I want to send, anc click in ''Send Numbers'' button, isn't it?

But, I can't see anything... :( 

Regards

Andrew Neil
Evangelist
Posted on March 04, 2013 at 16:12

''I'm new in that technology and this microcontroller ...  I've never worked with Realterm...''

Sounds like you are trying to do too many new things all at once !

What is your background - are you experienced with any other microcontroller(s)? Are you a competent 'C' programmer? etc...?

hibiscusblau
Associate II
Posted on March 05, 2013 at 11:40

Andrew, 

You're in right, maybe I run instead of walk. I'll try to change it. For this reasons, I last night thinking out start my program almost without all the rest of my code. But, maybe I should be test my module in the lowest level. 

Well, I only program my dsPIC with two uarts (in order to control some bits through Tera Term/hyperterminal/Real term program), a pin connnected to nBOOTLOADER(pin18 of STM32W) and a pic connected to nRESET (pin5 of STM32W) and a led. 

If I sent all the time the char ''127'' (0x07), I can see through oscillscope the Tx and Rx signals and I don't understand the RX behaviour:

0690X000006053JQAQ.png

hibiscusblau
Associate II
Posted on March 11, 2013 at 13:31

Hi, 

I've done some progresses, my first error is do not supply my zigbee module, the person who advice me, told me  is it not necessary. 

Ok, I reset my dsPIC and I detected (with oscilloscope) the following frame from STM32W108, but I don't know what them mean. 

1st: 000001001 --> start bit + 00000100 + stop bit (1) = 0x04

2nd: 0x04

3th: 0x04

4th: 0x04;

5th: 0x58

6th: 0x50

7th: 0x04

etc...

0690X000006053sQAA.png

Where I can find what each command mean?

Why the frecuency is 11.49KHz?

Thanks

hibiscusblau
Associate II
Posted on March 20, 2013 at 13:34

Hello everybody,

I've found out my problem, and I've achieved to connect that I wanted. Hardware connections: 0690X000006054RQAQ.png And the C software part:

void ZigPrimerContacte(){ 
switch (StatProva1){
case 0: 
ZigBootModeOFF(); //nBOOTMODE = 1
ZigBootModeON(); //nBOOTMODE = 0
nRESET = 1; // **** reset. 
nRESET = 0; // **** reset. 
nRESET = 1; // **** reset. 
StatProva = 1;
break; 
case 1: 
ResetBuff2();
comanda = 0x7F;
putcUART2 (comanda);
while (BusyUART2()); // M'espero mentres es transmet
while (UartTincDada2 () == 0); //mentres no m'arribi res... m'espero
StatProva1 = 2;
break;
case 2: 
delay_ms(100); //ho necessito perquè tingui temps d'agafar les dades....
if(UartReturnBuf_Rx2Char (0) == ACKvalue){
sprintf(sTxt, ''

 ACK ok 

'');
putsUART1((unsigned int *)sTxt);
StatProva1 = 3;
}else{
sprintf(sTxt, ''

 ACK ko 

'');
putsUART1((unsigned int *)sTxt);
StatProva1 = 99; 
}
break;
case 3:
comanda = 0x00; // 0x00
putcUART2 (comanda);
while (BusyUART2()); // M'espero mentres es transmet
StatProva1 = 4;
break;
case 4:
comanda = 0xff; // comanda get 0xff
putcUART2(comanda);
while (BusyUART2()); // M'espero mentres es transmet
StatProva1 = 5;
break;
case 5: if(UartTincDada2 () == 1){ //mentres no m'arribi res... m'espero 
StatProva1 = 6;
}else{
StatProva1 = 5;
}
break;
case 6: 
sprintf(sTxt, ''

 Comandes disponibles: 

'');
putsUART1((unsigned int *)sTxt); 
UartPintaDada2 (); //quan rebi alguna cosa ho pinto
delay_ms(100); //ho necessito perquè tingui temps d'agafar les dades....
UartReturnBuf_Rx2Copy();
//ZigPintaBytes ();
StatProva1 = 7;
break;
case 7 :
StatProva1 = 7;
break;
case 99:
StatProva1 = 99;
break;
}
}

And I can see it perfectly. I hope it's useful for somebody.
hibiscusblau
Associate II
Posted on March 20, 2013 at 13:36

Also, my configuration of the UART is:

U2MODEbits.UARTEN = 0;
// Step 1
U2BRG = 129; // Baud Rate Register
// Step 2
U2MODEbits.USIDL = 1;
U2MODEbits.WAKE = 1;
U2MODEbits.ABAUD = 1;
U2MODEbits.PDSEL = 0; // 0: 8-bit data, none parity
U2MODEbits.STSEL = 0; // 1 = 2 stop bits 0 = 1 stop bit
// Step 3 // Vull treballar per interrupció
IEC1bits.U2TXIE = 1;
IEC1bits.U2RXIE = 1;
IPC6bits.U2TXIP = 3; //prioritat
IPC6bits.U2RXIP = 4;
U2STAbits.UTXISEL = 0; //Transmit interrupt mode
//canvis
U2STAbits.ADDEN = 0;
U2STAbits.UTXBRK = 0;
U2STAbits.URXISEL = 0; // 0x interrupt flag bit is set when a character is received
// Step 4
U2MODEbits.UARTEN = 1;
// Step 5 
U2STAbits.UTXEN = 1;