I have several HM-TRP radio adapters (consisting of the HM-TRP chip with a female header connected to it) of the same version. I tested it in a mini circuit where the PC does direct I/O with the HM-TRP adapter. That circuit works because when the PC checks for characters, as soon as I power the circuit, I get "HM-TRP-V02!" on my screen as expected.
Now I'm trying to achieve the same thing with a microcontroller (AT89S52) but the first byte isn't being detected correctly.
In both tests, all speeds set for the adapter is 56Kbps
This is my relevant code fragment:
org 0h ljmp init org 03h ;put string near beginning so we can increment DPL instead of DPTR ;String we expect to see returned serially hmtrpstrval: db 'M-TRP-V02',00h ;Not sure if I should add the "H" ;returnable statuses RADIOOK equ 0h ;Radio is OK NORADIO equ 1h ;No radio or timeout MFRADIO equ 2h ;Bad character: radio malfunction checkradinit: ;setup pointer and make A=0 and R1=0 mov DPTR,#hmtrpstrval clr A mov R1,A gnb: mov R3,A ;Here, R3=0 and A=0. R3 is the delay counter movc A,@A+DPTR ;Get data from address DPTR jz exhmt ;If byte in = 0 then exit. we're ok. wgb: ;Here we could stall for at least 65281 clocks ;(about 32mS) since crystal used is 22.1184Mhz ;but if ANY character is received, we process it jbc RI,exsc djnz R4,wgb djnz R3,wgb ;here, more than 32mS passed which is way too long ;so assume we haven't received the character and ;exit mov R5,#NORADIO ret exsc: ;See if incoming data matches byte xrl A,SBUF jnz hmerr ;The byte matches inc DPL ;so we move to next character we expect to receive mov R1,A ;and reset the chance counter explained below sjmp gnb hmerr: ;It doesn't but we give the radio up to 65534 more chances ;because it could have processed one byte without us knowing clr A ;so make A=0 and read same code byte again djnz R2,gnb djnz R1,gnb ;Here, too many chances were given and at least the wrong set of characters ;were received so we return a radio fault mov R5,#MFRADIO ret exhmt: ;here the valid string is received so we return OK. mov R5,#RADIOOK ret init: mov PCON,#80h ;set PCON.7 for speed trick. maybe turn off? mov SCON,#50h ;enable serial port in mode 1 mov TMOD,#021h ;set timer 1 in mode 2 (auto reload) mov TH1,#0FEh ;set reload values to 0FEh mov TL1,#0FEh setb TR1 ;start timer lcall checkradinit
The capacitor directly powering the HM-TRP radio module is 100uF electrolytic rated at 16V.
I'm posting this question here because I'm trying to account for the worst case scenario in successfully detecting the adapter. Currently its hardwired in data mode (not config mode) and the only other way I can test it is to have a remote system with the same adapter to send data, but I want to avoid doing that at this time.
Is there something better I can do to my code to make the test more reliable? I'm more concerned with the timings of the characters.
I also verified that the HM-TRP adapter works because I put it back into my mini circuit again and tested it there.
Is my logic right with my code? or should I be more lenient and detect the end part of the string only? or should I detect the full string? Should TH1 or TL1 be changed for better alignment? Is the 100uF an incorrect capacitor value?
The basic oscillator setup to the micro is 22.1184Mhz crystal with 33pF ceramic capacitors between each crystal lead and ground.
Please let me know where I'm going wrong?