Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Tricky SPI communication with request and response structure.

Status
Not open for further replies.

davidmeetsall

Newbie level 2
Joined
Dec 1, 2016
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
37
Hi Friends,

I have to implement a request_response function for 8-bit PIC microcontroller. This function has two arguments one is request command structure and other is response structure which is filled after getting response. Its 8-bytes i.e.,
Code:
typdef struct{
uint16_t data0;
uint16_t data1;
uint16_t data2;
uint16_t data3;
}data_st;

extern data_st *request;
extern data_st *response;

request_response(&request, &response);
There are 3-4 set of request and response. Which is sent one by one.
When request0 is sent first response must be discarded as there is 8-bytes(64 bits) gap in response from the other system. When request1 is sent response0 is gotten. Same way request2 is sent response1 is received. Same way request..n ...response..n-1 and request_dummy will be sent in the last to receive response..n.

I have to collect the correct response for a request. Means need to map response0 for request0 , response1 for request1 and response2 for request2 for further processing.

How to manage this? Please help.

Thanks,
david.
 

Can't you use sizeof(your struct) and point to to proper location.
 

If I got this right, then the solution is simple. Create an array of request and responses and call the function as many times as needed. Something like.

Code:
extern data_st request[8];
extern data_st response[8];

request_response(&request[0], &response[7]);
request_response(&request[1], &response[0]);
//..................................
request_response(&request[7], &response[6]);

Note that the first call uses response[7], this could be your dummy response for the request 0 case.
 

Can you add another byte or two bytes to the structure and the SPI message?
If you can have multiple requests pending/waiting for a response at a time, just include an incrementing transaction ID number that is set by the Master when the request is done. The response will have to include the same transaction ID # in its response. Or, if your system is not to send another request until the first response is ready to be processed, you could either "poll" the device for a "ready"/complete" status, or you could dedicate an I/O pin on the microcontroller to be activated when a response is ready to be read from the target device.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top