As nothing seem's to work... (not using simulation program now but real hardware)
Using now the smallest program to test what's wrong:
Code:'**************************************************************** '* Name : master.BAS * '* Author : Herve Helleboid * '* Notice : Copyright (c) 2013 HYTEM * '* : All Rights Reserved * '* Date : 02/11/2013 * '**************************************************************** DEFINE OSC 64 TRISA = %00000000 TRISB = %00000000 TRISC = %10010000 TRISD = %10000000 TRISE = %00000000 ANSELA = %00000000 ANSELB = %00000000 ANSELC = %00000000 ANSELD = %00000000 ANSELE = %00000000 ' configuration USART1 (communication RS232 external) RCSTA1 = $90 ' Enable serial port & continuous receive TXSTA1 = $20 ' Enable transmit, BRGH = 0 SPBRG1 = 103 ' 9600 Baud @ 64MHz, 0,16% SSPIF VAR PIR1.3 ' SPI interrupt flag SSPEN VAR SSP1CON1.5 ' SSP Enable bit SS0 var PORTB.3 LED VAR PORTE.0 slave var byte i VAR BYTE ' loop counter a VAR BYTE[6] ' Holds 6 characters read from slave BF VAR SSP1STAT.0 HIGH SS0 'slave not in use HIGH LED PAUSE 300 LOW LED hserout ["rdy",13,10] Pause 50 SSP1CON1 = %00100010 SSP1STAT = %00000000 SSPIF = 0 ' clear buffer full status mainloop: pause 200 low SS0 pauseus 5 SSP1BUF = "?" while BF = 1 : wend pauseus 10 SSPIF = 0 high SS0 hserout [SSP1BUF," ",dec SSP1BUF,13,10] ' display received char toggle led GoTo mainloop ' do it forever '*********************************************************************************** ' Name : SLAVE.pbp ' Compiler : PICBASIC PRO Compiler 2.6 ' Assembler : PM or MPASM ' pic18f45k22 @ 16MHz PLLx4 = 64MHz ' DEFINE OSC 64 TRISA = %00100000 TRISB = %00000000 TRISC = %10011000 TRISD = %10001000 TRISE = %00000000 ANSELA = %00000000 ANSELB = %00000000 ANSELC = %00000000 ANSELD = %00001000 ANSELE = %00000000 ' Allocate RAM dataout VAR BYTE[8] ' Data out array SSPEN VAR SSP1CON1.5 ' SSP Enable bit CKP VAR SSP1CON1.4 ' Clock Polarity Select SMP VAR SSP1STAT.7 ' Data input sample phase CKE VAR SSP1STAT.6 ' Clock Edge Select bit SSPIF VAR PIR1.3 ' interrupt flag - last bit set i VAR BYTE ' loop counter a VAR BYTE[6] ' Holds 6 characters of data led var PORTA.4 BF VAR SSP1STAT.0 SSP1CON1 = %00000100 ' configure SPI slave with SS CKP = 0 ' clock idle low CKE = 1 ' transmit on idle to active transition SSPIF = 0 ' clear SPI interrupt SMP = 0 ' sample in middle of data SSPEN = 1 RCSTA1 = $90 ' Enable serial port & continuous receive TXSTA1 = $20 ' Enable transmit, BRGH = 0 SPBRG1 = 25 ' 38400 Baud @ 64MHz, 0,16% HIGH LED PAUSE 300 LOW LED mainloop: SSP1BUF = "!" ' send reply $21 dec = 33 while BF = 1 : wend PAUSEUS 10 SSPIF = 0 toggle led goto mainloop
Master send "?" and need to receive "!"
doing it forever
AS I can see on my logic analyzer
MASTER send $3F (OK it's ? or decimal 63)
SLAVE send $21 (OK its ! or decimal 33)
This is measured with USBEE SX.
As I have a RS232 hardware connected to the PIC master (TX1) my master prog send to RS232 the received character
instead of receiving "!" (dec 33) it is always " " (dec 32)
sometimes also receiving strange characters
So... I was thinking that last bit is not recognized but:
If I change (slave prog) the character "!" by example by "W" or "0" it works fine every time !
I tried to send other different characters and for some of them, it's good...
For others it's decimal value -1 or decimal value + 1
Any help ?
Regards




Bookmarks