Serial data sending#do someone came across programming 16f676 with TRH031M?


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    9

    Unhappy Serial data sending#do someone came across programming 16f676 with TRH031M?

    Dear experts,

    Currently I am trying to program pic16f676 as a microcontroller to send serial data from TRH031M (kinda 13.56MHz transmitter)
    http://www.farnell.com/datasheets/460824.pdf

    Im using SPI serial interface in TRH031M and I faced difficulties in figuring out my coding. Kindly help.

  2. #2
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    The answer is obvious. There's an error in your code.

  3. #3
    Join Date
    Apr 2014
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    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)

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    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.

  5. #5
    Join Date
    Apr 2014
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    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.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    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.

  7. #7
    Join Date
    Apr 2014
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    Hi Henrik,

    Thanks alot! My brain isn't functioning well just now. Sorry for the confusion.

  8. #8
    Join Date
    Apr 2014
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    Hi Henrik,

    Now considering I have successfully received and stored the data in PIC16f877 as "ActualData" and I wish to send the stored data to the "slave (TRH031M)".
    Can I use SHIFTIN/OUT method to shift data into SDO pin and send to trh031m? Following is my coding:

    ************************************************** ********************************************
    'send received data from MU to TRH031M (master to slave)
    ActualData var word[8]
    j var byte[8]
    B0 var byte

    send1:
    SHIFTIN SDI, SCK, MSBPRE, [ActualData\8]
    j=ActualData
    SHIFTOUT SDO, SCK, MSBFIRST, [j]

    SSPBUF = "?" ' send ? to start conversion
    GoSub letclear ' wait for buffer to clear
    IF SSPBUF<>"!" Then send1 ' wait for reply (!)

    For j = 0 to 7 ' loop for 8 characters
    SSPBUF = 0 ' write to SSPBUF to start clock
    GoSub letclear ' wait for receipt
    B0[j] = SSPBUF ' store received character in array
    Next j ' get next character
    Return

    letclear:
    IF SSPIF = 0 Then letclear ' wait for SPI interupt flag
    PauseUs 25 ' 25uS fudge factor
    SSPIF = 0 ' reset flag
    Return

    ************************************************** ************************************

    Regards/

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    Hi,
    I don't know if it's you or me who are the most confused right now.....
    You seem to be mixing SHIFTIN/SHIFTOUT with the use of the MSSP module, use either or. And, previously you said you used SEROUT on another PIC to send data, then you can't use SHFTIN to receive it - if that's what you're trying to do. And, no, you can't use any of the methods to shift data into the SDO pin since that is the data output pin.
    Code:
    ActualData var word[8]
    j var byte[8]
    B0 var byte
    Any reason for ActualData to be WORDS?

    Code:
    send1:
    SHIFTIN SDI, SCK, MSBPRE, [ActualData\8]
    j=ActualData
    SHIFTOUT SDO, SCK, MSBFIRST, [j]
    Not sure what the purpose of this is but there's no reason to assign the value of ActualData to J and then send J out using SHIFTOUT, you could just as well shift out ActualData directly (instead of a copy of it).

    Code:
    For j = 0 to 7 ' loop for 8 characters
    SSPBUF = 0 ' write to SSPBUF to start clock
    GoSub letclear ' wait for receipt
    B0[j] = SSPBUF ' store received character in array
    Next j ' get next character
    Return
    Here you're treating B0 as an array when it's decalred as a BYTE. This is a critical error as it will write to memory location "beyond" B0 and corrupt what ever is there. PBP does not do any boundry checks on arrays so you need to be careful.

    This post probably isn't of much help to you but I've quite honestly lost track of what exactly you're trying to do. Now, we've got SERIN, SHIFTIN/SHIFTOUT and the use of the MSSP module in the mix - all at once and I'm struggeling to keep up. Again, I suggest that you get used to various ways of doing SPI by interfacing something simpler than the TRH031M - which, by the way, I've never used so I don't know how it works. But I looked, briefly, at the datasheet and nowhere can I find that you're supposed to send "?" to start a "conversion" - I thought the chip was for RFID communications, not a converter....

    /Henrik.

  10. #10
    Join Date
    Apr 2014
    Posts
    9


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    Hi,

    Sorry Henrik for making you confused. I am not sure that I can use SERIN with SHIFTIN/OUT so I mistakenly mixed them up.

    Actually what Im doing is transmit a data at 13.56MHz by using TRH031M and the data is from pic16f877. Since trh031m has 4 type of modes, SPI,parallel etc, i configured my hardware to perform SPI mode. So Im trying to use "master slave" communication to send my data from PIC to trh031m as trh031m already pre-configured as a "slave" by default which u told me in the previous comment.

    Can you kindly teach me what is the correct way to send my received data from PIC to trh031m? Do "master slave" communication work in performing my task?

    appreciate your kind helps.

    Regard.

  11. #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Serial data sending#do someone came across programming 16f676 with TRH031M?

    Hi,
    All I can say is that the PIC and PBP supports SPI communcation, either by using SHIFTIN/SHIFTOUT or using the MSSP peripheral module built into most devices. That gives you the interface between the PIC (master in this case) and the TRH031M (slave in this case). I see no reason for it not to work, however there are occasions where SHIFTIN/SHIFTOUT is NOT an option because the the slave devices is shifitng in and out data at the same time, in those cases you must use the MSSP module because the SHIFTIN/SHIFTOUT either shift data in OR shifts data out they can't do both simultanously.

    But, the TRH031M is a complicated device, it's not as simple as just "send some data" to it. It needs setting up, it needs commands sent to it, it needs data sent to it, it needs new commands sent to it, it needs to be polled for status and so on. You absolutely must read and understand the datasheet or you won't be able to make this work. Again, I've never used the device so *I* don't know how it works, I've just very briefly browsed thru the datasheet.

    I strongly suggest you put your PIC, a 74*595 (serial in, parallel out) and a 74*165 (parallel in, serial out) shiftregisters, a couple of LEDs and a couple of switches on a breadboard and get used to communicating with those. Use SHIFTOUT to write data to the 74*595 and SHIFTIN to read data from the 74*165. When you have that working and understand how it works, try the MSSP module instead of SHIFTIN/SHIFTOUT. With that you'll be able to write one byte to the 74*595 and read one byte from the 74*165 all in one go - which MIGHT be what's needed for the TRH031M - I'm not sure.

    THEN get back to the TRH031M.

    /Henrik.

Similar Threads

  1. Problem on sending data on serial port
    By bwaxing in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd May 2011, 21:05
  2. Ir problem sending data
    By Mus.me in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th December 2009, 05:27
  3. 16F676 programming problem
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th May 2009, 17:39
  4. VB sending serial data to PIC
    By Tissy in forum Serial
    Replies: 7
    Last Post: - 8th March 2006, 18:31
  5. Sending data over USB via VB
    By Tissy in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 12th September 2005, 01:00

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts