PDA

View Full Version : Dual USART, Second USART sends but not receives, PIC18F24K22



svjohngalt
- 12th January 2018, 02:17
My application is utilizing both USARTs for this chip. The primary USART is working fine. The second USART will transmit but will not receive. I sususpect I have an issue with the configuration. I did see this note for the RX2 pin in the documentation with Note 2 below for the RX2 pin. I do not know what this information means.


2: Alternate pin assignment for P2B, T3CKI, CCP3 and CCP2 when Configuration bits PB2MX, T3CMX, CCP3MX and
CCP2MX are clear.

Thanks
George

My configuration and code is:
'Configuration
DEFINE FOSC INTIO67
OSCCON = 110010 ' Set internal 8Mhz OSC




Define OSC 16


DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
define HSER_BAUD 9600
DEFINE HSER_CLROERR 1


DEFINE HSER2_RCSTA 90h
DEFINE HSER2_TXSTA 24h
define HSER2_BAUD 9600
DEFINE HSER2_CLROERR 1






ANSELA = 000000
ANSELB = 000000
ANSELC = 000000 ' Turn Off A2d


ADCON2 = 101101
ADCON1 = 001000
ADCON0 = 011000




TRISA = 111111 ' Setup TRIS
TRISB = 110000
TRISC = 111111


PORTA = 100000 ' Setup ports
PORTB = 000000
PORTC = 000000




Init_9800
Flag = 0
low led1
pause 100
'Initialization Process
'Send 0 then check hserin2 for a 13
'Increament x with each 13 received, once 13 is received 3x then OEC = 1
'Then wait for $43 for Report Transfer On
'Then wait for $42 for Touch report on
'At this point, OEC = 2 and is considered initialized
hserout2 [hex $0]
hserin2 100, main, [hex char2]
hserout2 ["input was", hex char2]
if char2 = $13 then
OEC = 1
x = X + 1
if X > 2 then
OEC = 2
X = 0
high led4
endif
endif
goto main
return

sayzer
- 12th January 2018, 05:30
TRISB.7 = 1
TRISC.7 = 1


RX1 and RX2 Pins = input pins.

Dave
- 12th January 2018, 11:14
I only see 6 of the 8 TRIS bits being set for each port.

svjohngalt
- 12th January 2018, 12:34
Something happened in the cut and paste, all 8 TRIS bits are set.
I did change the bits to inputs and it didn't resolve the issue:
TRISA = %11111111 ' Setup TRIS
TRISB = %11110000
TRISC = %11111111

Any other suggestions on why hserin2 may not be working?

Thanks
George

richard
- 12th January 2018, 12:52
no 1
http://www.picbasic.co.uk/forum/showthread.php?t=19594
no 2

OSCCON = 110010 ' Set internal 8Mhz OSC




Define OSC 16

what is it 8 or 16 ?

no 3

'Configuration
DEFINE FOSC INTIO67
that's not a configuration , it does nothing


no 4

hserin2 100, main, [hex char2]

main does not exist in the snippet , who knows what goes on there

no 5

given that hserin2 does infact work correctly when used correctly , the fault probably lies in the code not shown

richard
- 12th January 2018, 13:06
also, char2 we cant see how it was declared but if its a byte then it can only receive a single hex digit
it may never be $13 it may only be 0 to F
$13 sent as serial hex is ascii 0x31,0x33 ie two chrs

you need to be sure what you actually sending

I'd try this if hex is whats sent
hserin2 100, main, [hex2 char2]
hserout2 ["input was", hex char2]
if char2 = $13 then

sayzer
- 12th January 2018, 15:30
Define OSC 16


DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
define HSER_BAUD 9600
DEFINE HSER_CLROERR 1


DEFINE HSER2_RCSTA 90h
DEFINE HSER2_TXSTA 24h
define HSER2_BAUD 9600
DEFINE HSER2_CLROERR 1

return


Sinde you say that UART1 is working fine with your config settings, then UART2 should also be working fine with the same config settings.
Change your lines to




DEFINE OSC 16

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 160 ' 9600 Baud @ 16MHz, -0,08%
SPBRGH = 1
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER2_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
DEFINE HSER2_SPBRG 160 ' 9600 Baud @ 16MHz, -0,08%
SPBRGH2 = 1
BAUDCON2.3 = 1 ' Enable 16 bit baudrate generator

svjohngalt
- 12th January 2018, 17:02
It is now working. It was the issue of sending bytes and data mismatch. I had HSERIN2 100, main, [HEX char2] with char2 defined as a byte. When I dropped the HEX modifier, it worked properly and that is my last issue to resolve. My project is not complete and thank you everyone for your input.

Thanks
George