Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Communication with PIC24HJ256GP210

Solved!
Go to solution

Hi,

 

I need do the SPI Communication with PIC24HJ256GP210 hardware in LabVIEW 2010 with NI USB 8451.I would like to send 8 byte data and receive 8 byte data from PIC.I will be sending data byte by byte by changing the Chip Select(CS) signal.Before sending data I will be sending ENQ(Enquire as 3A) for checking PIC status then after receiving ACK(Acknowledge as A1),I will send the data packet.

 

 My testing Procedure given below,

 

  • Setting Clock Polarity to Zero (IDLE LOW), Clock Phase to One (Second Edge), and Clock Rate 1MHz in NI USB 8451 device
  • Sending 3A (ENQ) data and followed by meaningless data byte by byte also changing Chip Select state
  • No Explicit delay has provided since sending API takes 20msec to execute
  • Receive the ACK (A1) from Sensor
  • Send DataPacket [ Eg:A5,03,02,00,00,A6,2C,DD] byte by byte also changing chip select signal
  • No Explicit delay has given between each byte since sending API takes 20msec to execute
  • Sending 8 bytes meaning less data byte by byte and receiving byte by byte data from PIC
  • Received all the 8 bytes data with incorrect value

Please review my testing procedure and give your input if you have worked with SPI or if you have any input for my query.

 

Thanks in Advance.

 

Note: Attached my code with this mail for your reference.

 

Regards,

Natarajan.

0 Kudos
Message 1 of 3
(7,374 Views)

Hello Natarajan,

 

Are you writing the code in the PIC24HJ256GP210? 

 

In any case, it is possible the PIC24HJ256GP210 is returning your valid data during "Send DataPacket".  You could always try looking at that data in LabVIEW:

 

(I've modified the code to send all the 8 bytes of the data packet.  This is more efficient.  Why are you doing it "byte by byte".  Is it to toggle chip select after every byte? Is that necessary?)

SPI.PNG

 

If that doesn't work, then we may need to look at what the PIC24HJ256GP210 is doing...

O. Proulx
National Instruments
www.ni.com/support
0 Kudos
Message 2 of 3
(7,238 Views)
Solution
Accepted by topic author natarajan.ramasamy@honeywell.com

Hello O_Proulx,

 

Thanks for your Reply.

 

In SPI communication after sending the data we need to send again meaningless bytes that is equivalent to how many bytes we would like to receive from the Response System.So we can't read the data in the same VI as you mentioned in the code.

My problem has been solved.Meaningless byte i need to send as "AB".beacuse the HEX file has been developed in that way.

 

Regards,

Natarajan.

0 Kudos
Message 3 of 3
(7,235 Views)