diff src/eeprom_rs232.asm @ 656:8af5aefbcdaf default tip

Update to 3.31 beta
author heinrichsweikamp
date Thu, 27 Nov 2025 18:32:58 +0100
parents 75e90cd0c2c3
children
line wrap: on
line diff
--- a/src/eeprom_rs232.asm	Mon Apr 29 13:05:18 2024 +0200
+++ b/src/eeprom_rs232.asm	Thu Nov 27 18:32:58 2025 +0100
@@ -14,6 +14,7 @@
 #include "shared_definitions.h"
 #include "rtc.inc"
 #include "external_flash.inc"
+#include "convert.inc"	
 
 #DEFINE INSIDE_EEPROM_RS232
 #include "eeprom_rs232.inc"
@@ -368,6 +369,7 @@
 	btfss	speed_is_normal				; speed = normal?
 	bra		enable_rs232_1				; NO  - loop waiting for ISR to have adjusted the speed
 	bsf	TRISC,7
+	btfss	aux_flag							; use Bluetooth?
 	bcf		ble_npower						; YES - switch port to comm
 	bsf		PORTJ,2						;     - /Reset (required for very old OSTC sport)
 	movlw	b'00100100'					;     - TX configuration: TX enabled, async, high speed
@@ -507,11 +509,61 @@
 
 ;-----------------------------------------------------------------------------
 
+;------------------------------------------
+; Setup BLE name to new BLE (type 2) module
+;------------------------------------------
+    global  ble2_configure_name
+ble2_configure_name:
+    btfss   dn_flag		; dn mode?
+    return			; no, return
+    ;rcall    enable_rs232
+    bcf         NCTS            ; Clear to send
+    call	wait_1s
+    call	wait_1s
+    call	wait_1s
+    call	wait_1s
+    bcf	PORTB,6
+    nop
+    bsf	PORTB,6			; rising edge -> Command mode
+    ; point to config table
+    movlw   LOW     ble_AT2
+    movwf   TBLPTRL
+    movlw   HIGH    ble_AT2
+    movwf   TBLPTRH
+    movlw   UPPER   ble_AT2
+    movwf   TBLPTRU
+    rcall   ble_init_loop
+     ; Read serial from EEPROM
+    call    eeprom_serial_number_read	; read OSTC serial number
+    movff	mpr+0, lo
+    movff	mpr+1, hi
+    lfsr	FSR2,buffer+0
+    output_65535			; lo:hi converted to ascii into POSTINC2
+    SERIAL_CC_SEND  buffer+0
+    SERIAL_CC_SEND  buffer+1
+    SERIAL_CC_SEND  buffer+2
+    SERIAL_CC_SEND  buffer+3
+    SERIAL_CC_SEND  buffer+4
+    SERIAL_LC_SEND  .13				; CR
+    WAITMS      d'200'    
+    bcf	    PORTB,6			; falling edge -> Data mode
+    movlw   LOW     ble_AT3
+    movwf   TBLPTRL
+    movlw   HIGH    ble_AT3
+    movwf   TBLPTRH
+    movlw   UPPER   ble_AT3
+    movwf   TBLPTRU
+    rcall   ble_init_loop
+    return
+    
+	
+	
 ;-----------------------------------------------------------------------------
 ; Add new services and characteristics to new BLE (type 2) module
 ;-----------------------------------------------------------------------------
     global  ble2_configure
 ble2_configure:
+    bcf		aux_flag	; needed for enable_rs232
     rcall    enable_rs232
     bcf         NCTS            ; Clear to send
     call	wait_1s
@@ -521,20 +573,33 @@
     bcf	PORTB,6
     nop
     bsf	PORTB,6			; rising edge -> Command mode
-    
+
     ; point to config table
-    movlw   LOW     ble_AT1
-    movwf   TBLPTRL
-    movlw   HIGH    ble_AT1
-    movwf   TBLPTRH
-    movlw   UPPER   ble_AT1
-    movwf   TBLPTRU
-    rcall   ble_init_loop
-	
-    rcall   disable_rs232
-    bcf	    PORTB,6	    ; keep low for min. current consumption
+    movlw	LOW     ble_AT1
+    movwf	TBLPTRL
+    movlw	HIGH    ble_AT1
+    movwf	TBLPTRH
+    movlw	UPPER   ble_AT1
+    movwf	TBLPTRU
+   
+    btfsc	dual_comm		; dual-comm hardware?
+    rcall   	ble2_configure_at4	; YES - BLE-only module in dual-comm hardware, overwrite TBLPTRx!
+    
+    rcall	ble_init_loop
+    rcall	disable_rs232
+    bcf		PORTB,6	    ; keep low for min. current consumption
     return		    ; done.
 
+ble2_configure_at4:    
+    ; point to config table
+    movlw	LOW     ble_AT4
+    movwf	TBLPTRL
+    movlw	HIGH    ble_AT4
+    movwf	TBLPTRH
+    movlw	UPPER   ble_AT4
+    movwf	TBLPTRU
+    return
+    
 ble_init_loop:
         TBLRD*+
         movlw   0xFF	; end
@@ -559,18 +624,39 @@
 	SERIAL_CC_SEND	WREG
 	bra	ble_init_loop
     
+ble_AT4:	; config table
+    ; 0xFF at the end
+    ; 0xFE: 20ms delay
+    ; 0xFD: 1s delay
+    ; .13: cr character
+    db	"AT+UBTLN=OSTC nano",.13,0xFE				; "name command"
+    ;db	"AT+UFACTORY",.13,0xFE,0xFE				; Set to factory defined configuration
+    db  "AT+UMSM=1",.13,0xFE,0xFE				; start in Data mode
+    db	"AT+UBTLE=2",.13,0xFE					; Bluetooth low energy Peripheral
+    db	"AT+UDSC=0,0",.13,0xFE,0xFE				; Disable SPS Server on ID0 (and wait 40ms)
+    db	"AT+UDSC=0,6",.13,0xFE,0xFE				; SPs Server on ID0 (and wait 40ms)
+    db	"AT+UDSC=1,0",.13,0xFE,0xFE				; Disable SPP Server on ID1 (and wait 40ms)
+    db	"AT+UDSC=1,3",.13,0xFE,0xFE				; SPP Server on ID1 (and wait 40ms)
+    db	"AT&W",.13,0xFE						; write settings into eeprom
+    db	"AT+CPWROFF",.13					; save and reboot    
+    db	0xFD, 0xFD, 0xFF
+    
 ble_AT1:	; config table
     ; 0xFF at the end
     ; 0xFE: 20ms delay
     ; 0xFD: 1s delay
     ; .13: cr character
     db	0xFD,0xFD,0xFD,0xFD					; Wait 4 seconds
-    db	"AT+UDSC=0,0",.13,0xFE,0xFE				; Disable SPP Server on ID0 (and wait 40ms)
-    db	"AT+UDSC=0,3",.13,0xFE,0xFE				; SPP Server on ID0 (and wait 40ms)
-    db	"AT+UDSC=1,0",.13,0xFE,0xFE				; Disable SPS Server on ID1 (and wait 40ms)
-    db	"AT+UDSC=1,6",.13,0xFE,0xFE				; SPS Server on ID1 (and wait 40ms)
+    db	"AT+UDSC=0,0",.13,0xFE,0xFE				; Disable SPS Server on ID0 (and wait 40ms)
+    db	"AT+UDSC=0,6",.13,0xFE,0xFE				; SPs Server on ID0 (and wait 40ms)
+    db	"AT+UDSC=1,0",.13,0xFE,0xFE				; Disable SPP Server on ID1 (and wait 40ms)
+    db	"AT+UDSC=1,3",.13,0xFE,0xFE				; SPP Server on ID1 (and wait 40ms)
     db	"AT&W",.13,0xFE						; write settings into eeprom (and wait 20ms)
     db	"AT+CPWROFF",.13,0xFD,0xFD,0xFF				; save and reboot  (and wait 2 seconds)
-
-	
+ble_AT2:	; config table
+    db	0xFD,0xFD,0xFD,0xFD					; Wait 4 seconds
+    db	"AT+UBTLN=OSTC+ ",0xFF	    				; Start of "name command"
+ble_AT3:	; config table	
+    db	"ATO1",.13,0xFF						; Enable Data mode    
+    
 	END