Hardware SPi or Software (bitbanged) SPI ?Hi J2,
You have answered my worry!
What does READ SSPBUF CODE look like in Oshonsoft SPI?
C.
Hardware SPi or Software (bitbanged) SPI ?Hi J2,
You have answered my worry!
What does READ SSPBUF CODE look like in Oshonsoft SPI?
C.
=========================================================Yes and set the pins used in SPI slave as input/output as needed (TRISC, TRISCD)
Master reading slave's data or slave reading master's request data byte ?Hi J2,
Hardware.
C.
Hi J2,Master reading slave's data or slave reading master's request data byte ?
Of course you have to setup the slave, but not with Oshonsoft commandsHi J,
My question:
Hi J,
Are you saying that this section of the SLAVE program is not needed?
C.
================================================
=========================================================
Here is a snippet from the D/S:
SPI mode allows 8 bits of data to be synchronously transmitted and received simultaneously. To accomplish communication, typically three pins are used: • Serial Data Out (SDO) • Serial Data In (SDI) • Serial Clock (SCK) Additionally, a fourth pin may be used when in a Slave mode of operation: • Slave Select (SS)
Can you verify that I don't need SPI set-up in SLAVE, please?
C
Hi J,To setup slave you set SSPSTAT, SSPCON and the i/o directions of the SPI pins, which you have already done.
azi.LB = CAP2BUFL
SSPBUF = azi.LB
SSPBUF = CAP2BUFL 'SSPBUF and CAP2BUFL are both 8 bits registers.
Hi J2,Are you trying to send slave's CAP2BUFL value to Master ? If yes,
Why
?Code:azi.LB = CAP2BUFL SSPBUF = azi.LB
Why not
Do you want slave to send data to master when master request's data from slave or do you want slave to continuously send data to master ?Code:SSPBUF = CAP2BUFL 'SSPBUF and CAP2BUFL are both 8 bits registers.
Once again.Hi J2,
Here is the SLAVE CODE:
I am receiving SSPBUF and AZI from the HSEROUT on a computer terminal, so I think the DATA is in the SLAVE registers.
Now I need the MASTER CODE to READ it, please.
C
NOTE: ( ' ) means commented out. (It was a test)
-----------------------------------------------------------------------------------------------------
get_count:
'If SSPSTAT.BF = 1 Then
azi.LB = CAP2BUFL 'Read QUAD cntr, range 0000 through 3581
SSPBUF = azi.LB
Hserout "SSPBUF = ", SSPBUF, CrLf 'TEST<<<<<<<<<<<<<<
Hserout "#SSPBUF = ", #SSPBUF, CrLf 'TEST<<<<<<<<<<<<<<
Hserout "AZI = ", azi.LB, CrLf 'TEST<<<<<<<<<<<<<<
Hserout "#AZI =", #azi.LB, CrLf 'TEST<<<<<<<<<<<<<<"
'Endif
Goto get_count
---------------------------------------------------------------------------------------------------
What do you get with SPIreceive azi?Hi J2,
I've been trying different combinations of VARIABLES, REGISTERS etc, trying to get results, this was one of them.
All I want is the Quadrature encoder count 0 to 359, held in CAP2BUFL and CAP2BUFH to get into the MASTER via SPI.
C.
You can use the Oshonsoft Basic setup commands for the master or setup HW spi also for the master.Hi J,
Ok, thanks.
Am I correct that this is the same for both PICs?
C.
Hi J,You can use the Oshonsoft Basic setup commands for the master or setup HW spi also for the master.
When the master has been working before, I would not change it now, because it might cause new errors.
HW setup is wrong.Hi J,
Am I correct that this is:
Oshonsoft Basic setup commands for the master?
'SPI
''Define SPI_CS_REG = PORTD [USED WHEN IN SLAVE MODE]
''Define SPI_CS_BIT = 4[USED WHEN IN SLAVE MODE]
Define SPI_SCK_REG = PORTC
Define SPI_SCK_BIT = 3
Define SPI_SDI_REG = PORTC 'not used, but left in so OSH does not burp
Define SPI_SDI_BIT = 4
Define SPI_SDO_REG = PORTC
Define SPI_SDO_BIT = 5
SPIPrepare
And this is: HW spi also for the master?
TRISB = %00000000 'OUT 1=YLED 2=RLED
TRISC = %01000000 '6-C/S=IN
TRISD = %00001100 '3=SCK=IN,2=SDI=IN
'SPI
SSPCON = %00100100 'SPI Control register: 5=SPI EN,3210= 0100 (SPI SLAVE,SCK PIN,SS PIN EN)
SSPSTAT = %00000000
C.
Hi J,HW setup is wrong.
It is better to forget HW SPI now until the sw master works.
You can use the old working sw master, but check the pins which are wired to slave.
You can make a simple test to get one value slave->master
In slave write a value to SSPBUF eg. 0xAA or whatever and then stop the program
stop:
goto stop
In master cs slave
wait (1000)
SPIreceive data
Hserout data
stop: goto stop
Use the exact setup for sw master which has worked before in compass and BMP280.Hi J,
Regarding my previous question in #73:
Is either one or both of those statements true?
C.
Hi J,Use the exact setup for sw master which has worked before in compass and BMP280.
This has been mentioned before.Hi J,
My question was literally to find out what 'Oshonsoft Basic setup commands for the master' and 'setup HW spi also for the master' mean?
C.
Hi J,This has been mentioned before.
Oshonsoft Basic setup is only for master and is implemented in software by "bitbanging" the pins of ioports. The function and direction of the pins are from the define commands.
HW spi is using the unit inside the PIC and is defined by SSPSTAT and SSPCON and TRIS registers. The used pins are fixed ( SDI, SDO, SCK