2013-03-01 04:37 AM
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-run2013-03-01 06:54 AM
sprintf(sTxt, ''0x7F''); //commanda d'iniciació
Not ASCII, you need to send an 8-bit value, 0x7F or 1272013-03-01 09:37 AM
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,2013-03-01 09:48 AM
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.2013-03-04 04:30 AM
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... :( Regards2013-03-04 07:12 AM
''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...?2013-03-05 02:40 AM
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:2013-03-11 05:31 AM
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: 0x507th: 0x04etc...Where I can find what each command mean?Why the frecuency is 11.49KHz?Thanks2013-03-20 05:34 AM
Hello everybody,
I've found out my problem, and I've achieved to connect that I wanted. Hardware connections: 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.
2013-03-20 05:36 AM
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;