Hi,
This is what my circuit looks like:
![Name: USART network.JPG
Views: 12539
Size: 26.0 KB](https://www.picbasic.co.uk/forum/attachment.php?s=6ede7564996a4648746efe25362d9608&attachmentid=6709&d=1350867686)
- The 18F4550 sends 1 byte to the slaves on Master TX line.
- Both slaves receive the byte properly.
- 1st slave replies successfully with same byte on Master RX line.
Problem: communication is blocked if 2nd slave is added on Master RX line.
Note: 2nd slave does not reply to master yet, extra address byte will be added later so each slave will reply only when spoken to.
Master:
Code:
' 184550 external oscillator 20MHz
' 4K7 pull-up on RX
@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_1_2L & _VREGEN_ON_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H
@ __CONFIG _CONFIG3H, _CCP2MX_OFF_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
DEFINE OSC 48
ADCON1 = %00001111
INTCON2 = %10000000
TRISA = %00000000
TRISB = %00000000
TRISC = %11000000
TRISD = %00000000
TRISE = %00000000
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 25 ' 115200 Baud @ 48MHz, 0,16%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
DEFINE LCD_DREG PORTD ' Set LCD data port
DEFINE LCD_DBIT 0 ' Set starting data bit
DEFINE LCD_BITS 8 ' Set LCD bus size
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_RSREG PORTC ' Set LCD register select port
DEFINE LCD_RSBIT 1 ' Set LCD register select bit
DEFINE LCD_EREG PORTC ' Set LCD enable port
DEFINE LCD_EBIT 0 ' Set LCD enable bit
define LCD_COMMANDUS 1500 ' Set command delay time in microseconds
DEFINE LCD_DATAUS 50 ' Set data delay time in microseconds
DataIn VAR byte
DataOut VAR byte
low PORTC.2
Start:
Pause 2000
Main:
DataOut = PortC.2
LCDOUT $FE,$80,"This is the data out: ", dec1 DataOut
hserout [dec1 DataOut]
hSERIN [dec1 DataIn]
LCDOUT $FE,$C0,"This is the data in: ", dec1 DataIn
pause 1000
toggle PortC.2
GOTO Main
end
1st slave:
Code:
' 18F44K22 internal oscillator 64MHz
' 4K7 pull-up on RX
@ __CONFIG _CONFIG1H, _FOSC_INTIO67_1H & _PLLCFG_ON_1H & _PRICLKEN_OFF_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_SBORDIS_2L & _BORV_285_2L
@ __CONFIG _CONFIG2H, _WDTEN_OFF_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _HFOFST_OFF_3H & _MCLRE_EXTMCLR_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
DEFINE OSC 64
OSCCON = %01110000
OSCCON2 = %10000000
OSCTUNE = %11000000
INTCON2 = %10000000
ANSELA = 0
ANSELB = 0
ANSELC = 0
ANSELD = 0
ANSELE = 0
TRISA = %00001111 ' Set port A pins 0-3 to input, others output
TRISB = %00000000 ' Set port B pins to output
TRISC = %11111111 ' Set port C pins to input
TRISD = %00111111 ' Set port D pins 0-5 to input, others output
TRISE = %00000000 ' Set port E pins to output
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 138 ' 115200 Baud @ 64MHz, -0,08%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; PBP Re-entry for external interrupt
INCLUDE "Elapsed_INT-18.bas" ; Elapsed Timer Routines
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX1_INT, _ReceiveInterrupt, PBP, no
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
DataIn VAR byte
DataOut VAR byte
RS232Flag VAR byte
goto Start
ReceiveInterrupt:
hSERIN [dec1 DataIn]
RS232Flag = 1
@ INT_RETURN
Start:
Pause 1500
@ INT_ENABLE RX1_INT
mainloop:
if RS232Flag = 1 then
RS232Flag = 0
PortA.4 = DataIn
DataOut = DataIn
hserout [dec1 DataOut]
endif
Goto mainloop
end
2nd slave:
Code:
' 18F26K22 internal oscillator 64MHz
' 4K7 pull-up on RX
@ __CONFIG _CONFIG1H, _FOSC_INTIO67_1H & _PLLCFG_ON_1H & _PRICLKEN_OFF_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
@ __CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_SBORDIS_2L & _BORV_285_2L
@ __CONFIG _CONFIG2H, _WDTEN_OFF_2H
@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _HFOFST_OFF_3H & _MCLRE_EXTMCLR_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
DEFINE OSC 64
OSCCON = %01110000
OSCCON2 = %10000000
OSCTUNE = %11000000
INTCON2 = %10000000
ANSELA = 0 ' Digital I/O
ANSELB = 0
ANSELC = 0
TRISA = %00111111 ' Set port A pins 0-5 to input
TRISB = %00000000 ' Set port B pins to output
TRISC = %11000000 ' Set port C pins 6-7 to input, others output
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 138 ' 115200 Baud @ 64MHz, -0,08%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; PBP Re-entry for external interrupt
INCLUDE "Elapsed_INT-18.bas" ; Elapsed Timer Routines
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler RX1_INT, _ReceiveInterrupt, PBP, no
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
DataIn VAR byte
RS232Flag VAR byte
RS232Flag = 0
goto Start ' Jump over sub-routines
ReceiveInterrupt: ' [USART RX - interrupt handler]
hSERIN 50,No232,[dec1 DataIn]
RS232Flag = 1
No232:
@ INT_RETURN
Start:
Pause 1500
@ INT_ENABLE RX1_INT ; Enable USART Receive interrupts
mainloop:
if RS232Flag = 1 then
RS232Flag = 0
PortA.7 = DataIn
endif
Goto mainloop
end
This has been driving me nuts for several days. I've trimmed my programs down to this bare essential and I still can't see what I'm doing wrong.
Everything works beautifully as long as I don't add that 2nd slave on the reply line.
Robert
Bookmarks