it can't get simpler than this depending on distance / speed .Can you recommend something else that's better for connecting two PICs?
using serial tty ie hserin/out
Warning I'm not a teacher
I would get the two talking directly without any MIDI interface. Just connect the TX from the PIC running the transmission code, to the RX on the receiving PIC using a simple jumper wire. If you need to send data back the connect the receiving PICs TX pin to the RX pin on the other PIC. I would then use the HSEROUT and HSERIN commands to send data.
You could write a short test routine so that the receiving PIC sends a character to the transmitting PIC when its ready to receive data (say by pressing a button), the transmission is made and the data displayed on the LCD.
So your transmission PIC has something like
You would then have your receiving PIC set up so that when you want to receive data it sends a Q to the transmitting PIC. The transmitting PIC is always looking at the serial port buffer to see if there is something in it, and when it finds something jumps to the comms subroutine, which checks to see what character has been received an for a match. If its Q then it transmits the data. You could use other characters to jump to other routines and do other things if you wanted.Code:RCIF VAR PIR1.5 ' USART receive flag GIE VAR INTCON.7 ' Comms TempWD VAR WORD ' temporary WORD variable nTest var byte FOR TempWD = 0 TO 1000 IF RCIF=1 THEN GOTO coms ; Check to see if somethings in the buffer, if there is something goto Comms PAUSE 2 NEXT TempWD coms: HSERIN [nTest] SELECT CASE nTest CASE "Q" ; if Q then send data GOTO Term_TX: Term_TX Hserout [DEC3 insert variable here] ; sends three digits of variable eg 123
The only caveat here is that I've only ever sent numeric data this way. Sending ASCII or strings may need more work.
Whilst the code is clunky it could always be tidied up and made more efficient once you have the two talking.
Strange baudrate !
Using a EUSART calculator for your baudrate it gives these values for the port settings
I don't have PBP3 - so no idea if the formatting is the same or needs changingCode: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 39 ' 31250 Baud @ SPBRGH = 0 BAUDCON.3 = 1 ' Enable 16 bit baudrate generator RCSTA = $90 ' Enable serial port & continuous receive TXSTA = $20 ' Enable transmit, BRGH = 0 SPBRG = 39 ' 31250 Baud @ 0.0% SPBRGH = 0 BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
Please make sure that PIC to PIC directly connected work as expected.
Then move to MIDI interface.
Also be sure to connect TX to RX. Looks trivial but...
Ioannis
I removed the midi connections and just connected the TX of the transmitting PIC to the RC of the receiving PIC. Here is the code I'm using for each:
transmitting:
receiving:Code:define OSC 20 define HSER_RCSTA 90h define HSER_TXSTA 20h define HSER_BAUD 31250 DEFINE HSER_SPBRG 39 ' 31250 Baud @ SPBRGH = 0 ANSEL = %00000000 ANSELH = %00000000 TRISD = %00000000 TRISE = %00000000 TRISA = %00000000 TRISB = %00000000 TRISC = %10000000 main: hserout [dec 1] PORTA.0 = 1 pause 300 hserout [dec 0] PORTA.0 = 0 pause 300 goto main
So now it's sorta working. The LCD does display something. It displays "216" when it should be displaying "0" and it displays "217" when it should be displaying 1.Code:CLEAR define LOADER_USED 1 define OSC 20 define HSER_RCSTA 90h define HSER_TXSTA 20h define HSER_BAUD 31250 define HSER_CLROERR 1 DEFINE HSER_SPBRG 39 ' 31250 Baud @ SPBRGH = 0 define LCD_DREG PORTD define LCD_DBIT 0 define LCD_RSREG PORTE define LCD_RSBIT 0 define LCD_EREG PORTE define LCD_EBIT 1 define LCD_RWREG PORTE define LCD_RWBIT 2 define LCD_BITS 4 define LCD_LINES 4 define LCD_COMMANDUS 2000 define LCD_DATAUS 50 ANSEL = %00000000 ANSELH = %00000000 TRISD = %00000000 TRISE = %00000000 TRISA = %00000000 TRISB = %00000000 TRISC = %10000000 character var byte pause 250 lcdout $FE, 1 lcdout $fe, $d4, "ready to receive" pause 500 lcdout $fe, 1 pause 250 main: hserin [character] lcdout $fe, 1 lcdout $fe, $94, dec character goto main
Try setting a variable.
then use something likeCode:character var word
And similar for the receiving pic. I'm no expert, but I think that just having DEC 1 as you had simply means its setting the DEC command to use just 1 digit as decimal value of a variable, not a valueCode:hserout [dec character]
Last edited by Scampy; - 14th May 2018 at 20:44.
Bookmarks