Dear Charlie,
I am new in picbasicpro. Where can i find a sample SPI coding to be referred? Currently Im using TRH031M as "slave" in SPI mode and pic16f877 as a MCU (master in SPI mode)
Dear Charlie,
I am new in picbasicpro. Where can i find a sample SPI coding to be referred? Currently Im using TRH031M as "slave" in SPI mode and pic16f877 as a MCU (master in SPI mode)
Hi,
Start by taking a look in the PBP3 installation folder. There's sub-folder called EXAMPLES\GENERAL PBP.
The file shift.pbp demonstrates how to use the SHIFTIN/SHIFTOUT commands and the files spimast.pbp and spislave.pbp demonstrates how to use the SSP/MSSP module in the PIC to do SPI at the hardware level.
The PBP manual covers the use of SHIFTIN/SHIFTOUT and there should be plenty of example code around the forum. Probably not exactly the code you need but plenty to get ideas from. If you get stuck post specific questions and you'll most likely get plenty of help.
With that said, if you're new to PBP then perhaps getting up to speed by interfacing a simple shiftregister or something as a start might be a good idea.
/Henrik.
Hi Henrik,
As per my understanding, to perform SPI between a master and a slave, 2 programmable PICs are needed (1 for master& 1 for slave) while TRH031M I am using is kinda transmitter which cannot be programmed. So, can I send only data from my PIC16f877(master) to TRH031M without programming TRH031M? Kindly advice!
Thanks.
Last edited by Hanson; - 15th April 2014 at 09:28.
Hi,
With SPI there's always one master and one or more slaves. The master is always responsible for generating the clock. In your case the PIC would be the master and the TRH031M would be the slave. Master/slave has nothing to do with the direction of the data, it can go from master to slave, from slave to master or both ways.
So, yes, of course you can send and receive data to/from the TRH031M without reprogramming it - it's already "programmed" to act as a slave.
/Henrik.
Hi Henrik,
Thank you so much for the clarification made. Considering "slave(trh031m)" already received data from "master(16f877)" and I wish to send received data through TX1 of TRH031M, still I need to program one PIC to perform this task, isn't it?
Regards
Hi,
Yes, of course, you need to program the PIC to send and receive commands and data to/from the TRH031M according to the datasheet.
/Henrik.
Hi Henrik,
Let's say Im now sending a serial data "Hanson" and i set my start frame as "AAAAA" and end frame as "EEEEE". So the serial data Im sending is like:
"AAAAAHANSONEEEEE"
at sending side:
start:
SEROUT dataout,N300,["AAAAA","HANSON", "EEEEE"]
pause 100
goto start
My problem is at the receiving side, I wish to filter my received data before storing them. The only solution I have thought was "nested IF loop" but microcode studio don't support this kinda command rather just "IF...THEN". Right?
so, how can I write my coding to perform this data filtering task?
eg:
check if data_in[0]="A" ;if yes then proceed checking for second "A"
check if data_in[1]="A" ;if yes then proceed checking for third "A"
check if data_in[2]="A" ;if yes then proceed checking for forth and fifth "A"
check if data_in[13]="E" ;if yes then check for second "E"
.
.
.
check if data_in[16]="E" ;if all conditions matched (receive first 5 "A" and last 5 "E" properly) then store data_in
else loop back subroutine and repeat checking for first "A"
Regards
Bookmarks