News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Problem with hserin wait

Started by Giuseppe, Feb 20, 2024, 09:39 AM

Previous topic - Next topic

Giuseppe

Hi everyone, it is possible to wait 3 characters with the wait with this syntax ?

HSerIn 1000,imp_numeri,[Wait("OK",13,10)]

Thank you

Dolci

#1
yes.. the sample below is from a SIM900A routine I always use.

HSerIn 300,TIMEOUT,[Wait(CR,CR,LF),Str GlobalBuffer]

yours are waiting for 4 characters.

Giuseppe

Thanks Sweets for replying to me. In fact I was working with an 800 SIM. I wanted to create a system with 5 numbers stored in the white list with 3 rings to activate an exit and have confirmation with another 3 rings. Do you happen to have a list ready?

Giuseppe

when sending the command
HSerOut ["AT+CPBR=",Dec i,44,Dec i,13] to read the numbers stored in the sim. If there are no numbers the answer will be:
CR LF OK CR LF while if there are numbers the response will be:
+CPBR: 1,"3405211233",129,"Daniel" (EX).
So how do you use wait for two different responses?

Dolci

acknowledge only one.
if the reply is CR LF OK CR LF then ignore it (meaning no numbers on that address)

what is the exact reply of sim800 if you send HSerOut ["AT+CPBR=",Dec i,44,Dec i,13] and a number is stored on that location?

Giuseppe

The correct answer to the question HSerOut ["AT+CPBR=",Dec i,44,Dec i,13] is +CPBR: 1,"3405211233",129,"Daniel" .
Now I'm trying to receive via buffered interrupt

Giuseppe

Hi everyone, I'm trying to use an 800 sim module. I have no problems with Proc setsim800. The problem comes when I wait
HSerIn 500,imp_numbers,[Wait(0D,0A),Str rxbuffer] . In fact it keeps sending me back to imp_numeri, how to solve it?

Device = 16F1827

Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_ON, MCLRE_OFF, CP_ON, CPD_ON, BOREN_ON, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, PLLEN_OFF, STVREN_OFF,LVP_OFF , BORV_19

Xtal = 8

OSCCON = %01110010 
OPTION_REG = %00000111 

'---Set Port----------------------------------------------------

LATA  = %00000000     
LATB  = %00000000
TRISA = %00100000
TRISB = %11111011
WPUA = %00100000 
WPUB = %00000000 
CM1CON0.7 = 0     
CM2CON0.7 = 0     
SRCON0.7 = 0       
FVRCON = %00000000
Clear ANSELA     
Clear ANSELB
APFCON0 = 0     
APFCON1 = 0

'-----Set serial hardware-------

Declare Serial_Data 8         '
Declare Hserin_Pin PORTB.1    'PIN 7 Rx 16f1827
Declare Hserout_Pin PORTB.2   'PIN 8 Tx 16f1827
Declare Hserial_Baud 9600
Declare Hserial_TXSTA = %00100100
Declare Hserial_RCSTA = %10010000
Declare Hserial_Clear = On
Declare HSerial1_Terminator = CRLF

' Set up the PORT Pins
'----------------------------------------------------------------------------------------
 PORTA = 0                          ' PORTA.A All outputs low
 TRISA = %00100000                  ' PORTA 0,1&3 Inputs, Rest are Outputs
 TRISB = %00000010                  ' PORTB.1 RX seriale

'-----Set interrupt ------------------------

INTCON = %01000000
PIE1 = %00100000   '
PIE2 = 0
'PIE3 = 0     '
'PIE4 = 0     '
PIR1 = 0     '
PIR2 = 0
'PIR3 = 0     '
'PIR4 = 0     '
'-------Set symbol -------------------------------------------

Symbol GIE = INTCON.7     ' Global Interrupt Enable
Symbol PEIE = INTCON.6    ' Peripheral Interrupt Enable
Symbol RCIE = PIE1.5      ' USART Receive Interrupt Enable
Symbol RCIF = PIR1.5      ' USART Receive Interrupt flag
Symbol RX9D = RCSTA.0     ' 9th bit of received data (Can be parity bit)
Symbol TX9D = TXSTA.0     ' 9th bit of sent data (Can be parity bit)
Symbol BRGH = TXSTA.2     ' baudrate generator with smaller divident
Symbol TXIF = PIR1.4      ' USART Transmit Interrupt
Symbol TXIE = PIE1.4      ' USART Transmit Interrupt Enable
Symbol TXEN = TXSTA.5     ' Transmit Enable
Symbol T0IF = INTCON.2    ' TMR0 Overflow Flag
Symbol TMR0IE = INTCON.5  ' TMR0 Overflow Interrupt Enable
Symbol BUFLEN = 64
'----------------------------------------------------------------------------------------
Symbol RX_pic  = PORTB.1 'pin7
Symbol TX_pic  = PORTB.2 'pin8
Symbol RST_SIM = PORTB.3 'pin9
Symbol led_V = PORTB.4   'pin10  'led
Symbol led_R = PORTB.3   'pin11  'led
Symbol apici = $22       '
'-----------------------------------------------------------------------------------------
' Allocate variables
'-----------------------------------------------------------------------------------------
Dim cont As Byte
Dim n_nuber As Byte
Dim numero_1 [13] As Byte
Dim numero_2 [13] As Byte
Dim numero_3 [13] As Byte
Dim numero_4 [13] As Byte
Dim numero_5 [13] As Byte
Dim i As Byte
Dim flag As Byte
Dim iy As Byte
Dim cnt As Byte
Dim pos[2] As Byte         
Dim length As Byte         
Dim num_whitelist As Byte
Dim bufready As flag.1         
Dim no_number As flag.3       
Dim bufpntr As Byte             
Dim rxbuffer[BUFLEN] As Byte   
Dim rxchar  As Byte             
Dim rxsta  As Byte             
Dim car_1 As Byte
Clear                         

'---------------------------------------------------------------------------------------------
num_whitelist = 1
High led_V : High led_R  'Xchè led è un anodo comune                           

'---------------------------------------------------------------------------------------------------------
inizio:
 
HSerIn 1000,inizio,[Wait("SMS")]    'inizio modulo invia diverse conferme l'ultima è SMS Ready
DelayMS 20

test:                             'test seriale Sim800 e Mcu
HSerOut ["AT",13]
HSerIn 500,test,[Wait("OK")]
 
 
 setsim800()
 finder_num()
'----------------------------------------------------------------------------------------------------------------

Do
High led_V
DelayMS 200
Low led_V
DelayMS 200
Loop

'-----------------------------------------------------------------------------------------------------------------
Proc setsim800()
inizio1:
DelayMS 20
HSerOut["AT+IPR=9600",13]         
HSerIn 500,inizio1,[Wait(13,10,"OK",13,10)]
DelayMS 20
HSerOut["AT+CPBS=",34,"SM",34,13]
HSerIn 500,inizio1,[Wait("OK")] 
DelayMS 20
HSerOut["ATE0&W",13]             
HSerIn 500,inizio1,[Wait("OK")]
DelayMS 20
EndProc

'--------------------------------------------------------------------------------------------------------


Proc finder_num()

Clear no_number

imp_numeri:
   
For i = 1 To 5
   
   DelayMS 300     
   Clear rxbuffer 
 
  HSerOut ["AT+CPBR=",Dec i,44,Dec i,13]    '
   
  HSerIn 500,imp_numeri,[Wait(0D,0A),Str rxbuffer]
   
 '-----------------------------------------------

  car_1 = rxbuffer[2]  '

   Select car_1
    Case $4F
      Continue
                                         
    Case $02B                           
     Clear cnt
     Set no_number                   
    For iy = 0 To 63                 
     If rxbuffer[iy] = apici Then   
      pos[cnt] = iy                 
      cnt = cnt + 1                 
     EndIf
    Next iy
   EndSelect
'---------------------------------------------------------
  Select i     
   Case 1                                   
     For iy = pos[0]+1 To pos[1]-1
       numero_1[iy] = rxbuffer[iy]
     Next iy
   
   Case 2
      For iy = pos[0]+1 To pos[1]-1
       numero_2[iy] = rxbuffer[iy]
      Next iy 
   Case 3
     For iy = pos[0]+1 To pos[1]-1
       numero_3[iy] = rxbuffer[iy]
     Next iy
   Case 4
     For iy = pos[0]+1 To pos[1]-1
       numero_4[iy] = rxbuffer[iy]
     Next iy 
   Case 5 
     For iy = pos[0]+1 To pos[1]-1
       numero_5[iy] = rxbuffer[iy]
     Next iy 
  EndSelect

High led_R

Next i

DelayMS 300

HRSOutLn Str numero_1
DelayMS 50
HRSOutLn Str numero_2
DelayMS 50
HRSOutLn Str numero_3
DelayMS 50
HRSOutLn Str numero_4
DelayMS 50
HRSOutLn Str numero_5

EndProc



Giuseppe

I wonder if
HSerIn 500,imp_numbers,[Wait(0D,0A),Str rxbuffer] can receive several bytes of a byte array ?

Giuseppe

I also tried this waiting for the CP characters.
HSerIn 500,imp_numeri,[Wait("CP"),Str rxbuffer] I didn't solve the same
But it doesn't find them even if the analyzer sends them from the module
rxbuffer is 64 bytes, the string I receive is shorter, can it create problems?

Giuseppe

this is an example of a string that I need to receive  : CRLF+CPBR: 1,"3405310231",129,"Giuseppe"