Trasfering 100 bytes of data through SPI between two 1769 MCUs

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trasfering 100 bytes of data through SPI between two 1769 MCUs

2,567 Views
abhinavdubey
Contributor II

Hi,

 

I have established SPI communication between two 1769 MCUs, I send one char and slave sends back some other character. Now, my  end application needs 100 bytes data to transfer from master 1769 to slave 1769 within specific  guard time of 10ms and slave send back some acknowledgement, If slave failed to respond within guard time, timeout error should occur. .

 

Question

 

To generate time guard I'm using timer 1, once data send calculated time send to uart, How to calculate time using timers,  I mean how much time taken by  master  to send 100 bytes to slave must be calculated and send on to the uart???

 

 

thanks in advance.

Tags (4)
6 Replies

1,751 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Abhinav Dubey,

    Thank you for your interest in NXP LPC product, I would like to provide service for you!

  1. How much time taken by  master  to send 100 bytes to slave

    The time is determined by your SPI baud rate, I suggest you configure your SPI baudrate to about 300Khz. This is enough to transfer 100bytes data to the slave in 10ms.

  2. Operation method

    When you want to send 100Bytes data from the master, then enable the timer in the master and configure it as the 10ms gard time, after send 100Bytes data, then send another byte data to slave, this byte is used to check the ACK from slave, in your slave, after you receive the 100 bytes data, then give the ACK data to the master when the 101 bytes clock from master.

    When Master send the ACK data, then use a flag to indicate that the slave have receive the 100bytes data successfully.

    In the master, after the 10ms is reached, check the slave ACK flag, if it indicate that the data is received by the slave, it is OK, otherwise it means the slave failed to response with the guard time.

Wish it helps you!

If yous still have question, please contact me!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,751 Views
abhinavdubey
Contributor II

Hi,

thanks for your reply, It's very useful.

I can determine time by SPI baud rate, but is there any way I can calculate time between two bytes transfer by using microcontroller timers ?? I want to calculate exact time to transfer one byte from master controller to slave.

Thanks

Abhinav

0 Kudos

1,751 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Abhinav,

    If you don't want to use the baudrate as the time calculator, you still can do it what I have told you.

    Before master send date, enable the timer, then master send one byte to slave, and wait the slave send back the data, after the master receive the data from the slave, then disable the timer, get the counter, and calculate the exact time.

Wish it helps you!

If you still have question, please contact me.


Have a great day,
Jingjign

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,751 Views
abhinavdubey
Contributor II

Hi,

thanks for reply, It's always useful.

I stuck at basic stage, when I am sending one byte from master, at slave end received same byte, but when I send multiple bytes from master side, at slave side 1st two bytes are received as in sending order but after two bytes some bytes are lost and after random amount of time I receive random sequences, garbage values, after few minutes I only receive 1st byte.

how I'm sending

AT MASTER SIDE

unsigned char transmit[4]= {'A','B','C'};

unsigned char I=0

slave _LOW;

for(I=0;I<=4;i++)

{

SPI_WRITE(LPC_SPI, transmit[I]);

}

Slave_HIGH;

AT SLAVE SIDE

unsigned char receive[4];

receive[0]=SPI_READ(LPC_SPI,0xFFFF)

printf("received byte= %c", receive[0]);

at slave side I tried below code as well but didn't work.

for(I=0;I<=4;i++)

{

receive[]= SPI_READ(LPC_SPI, 0xFFFF);

printf(("received byte= %c", receive[I]);

}

thanks

Abhinav

0 Kudos

1,751 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Abhinav,

 

Please comment the printf in the slave for(;;) code:

for(I=0;I<=4;i++)

{

receive[]= SPI_READ(LPC_SPI, 0xFFFF);

//printf(("received byte= %c", receive[I]);

}

Because printf normally need time, it is the delay, if the delay time is so long, it will caused your next time receive[]=SPI_READ data is not correct.

Please comment it, and try again on your side.

Have a great day,
Jjingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,751 Views
abhinavdubey
Contributor II

could I get any reply pls?????

0 Kudos