Strange SPI behaviour in LPC8N04 driver?

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

Strange SPI behaviour in LPC8N04 driver?

Jump to solution
1,068 Views
mrunal_ahirrao
Contributor II

I am working with SPI of LPC8N04. For it I downloaded the Board support package and from that I got the drivers for SPI. And in the ssp_8Nxx.c file there is the 

uint32_t Chip_SSP_WriteFrames_Blocking(LPC_SSP_T *pSSP, uint8_t *buffer, uint32_t buffer_len)

And I was facing issues in using it. Problem was that data transmitted was not correct for example if the buffer has 0x01 transmitted was 0x1F ! And while debugging the code I found that:

At Line 235, 

 

uint8_t *wdata8;

wdata8 = &buffer;// I Added '&' before buffer 

Without & the wdata8 will not hold the data pointed by buffer, so by adding & I am assigning the address of buffer which will point to the data I need to transmit.

Labels (1)
Tags (1)
1 Solution
911 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Mrunal Ahirrao

The function is expecting a pointer not a macro or any other type of data. Since you are not sending a pointer  you need to add the & to access the address where your macro was saved. But, if later you want to send a buffer you may have problems due to you modify the driver. The best idea will be to send a buffer instead of a macro, like shown below. 

uint8_t txbuff[] = "1";Chip_SSP_WriteFrames_Blocking(LPC_SSP0, txbuff, sizeof(txbuff)-1);‍‍

Hope it helps!

Victor.

-----------------------------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------------------------- 

View solution in original post

3 Replies
911 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Mrunal Ahirrao,

How are you calling the function Chip_SSP_WriteFrames_Blocking in your program? The variable buffer is already a pointer, so you don't have to use the & operand. For example, I have the following lines of code: 

uint8_t ptr[] = "Hello World";
uint8_t *ptr2;
ptr2 = ptr;‍‍‍‍‍‍‍‍‍

Where the address of ptr is the following

pastedImage_1.jpg

And once you run the line ptr2 = ptr; the value of ptr2 is the following

pastedImage_2.jpg

I think what is happening in your case is that when you called the function Chip_SSP_WriteFrames_Blocking  you passed as argument  the value of the buffer instead of the address and in that case you need the & operand, but this is not the correct way to pass the argument buffer. 

Regards, 

Victor. 

0 Kudos
911 Views
mrunal_ahirrao
Contributor II

Hi victorjimenez‌,

I am passing it like this:

Chip_SSP_WriteFrames_Blocking(LPC_SSP0, (uint8_t*)PWR, 1);

The PWR is a macro whose expansion is 0x01 and it is one byte only, not array of values. So I think due to this I needed the & there. If this is not the correct use case then how do I use it?

0 Kudos
912 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Mrunal Ahirrao

The function is expecting a pointer not a macro or any other type of data. Since you are not sending a pointer  you need to add the & to access the address where your macro was saved. But, if later you want to send a buffer you may have problems due to you modify the driver. The best idea will be to send a buffer instead of a macro, like shown below. 

uint8_t txbuff[] = "1";Chip_SSP_WriteFrames_Blocking(LPC_SSP0, txbuff, sizeof(txbuff)-1);‍‍

Hope it helps!

Victor.

-----------------------------------------------------------------------------------------------------------------------

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

-----------------------------------------------------------------------------------------------------------------------