EmbDev.net

Forum: µC & Digital Electronics Wrong value received in SPI receive register


von Aditya K. (stadkama)


Attached files:

Rate this post
useful
not useful
Hello,

I am building an SPI communicaton between MCU-ATSAM4E8C (master) and 
Slave device -bmi160 inertial sensor.

Debugger -atmel ice and MCU Device Programming Interface- jtag.


Issue:
1.During debugging, the receive data register always shows 0xff in the 
receive register(spi_rdr) even though the inertial sensor is sending 
0xd1 that I verified in oscollocope.

2. During debugging , the Receive data register full bit(RDRF) is not 
set. However if I don't debug and check using if condition the bit will 
be set.

Please let me know what is the cause for this issue.
Thank you.

von Jim M. (turboj)


Rate this post
useful
not useful
Reading the RDR register with the debugger clears the RDRF bit. Thats 
why I told you not do do that: https://embdev.net/topic/383997#4382228

von Aditya K. (stadkama)


Rate this post
useful
not useful
Yes you had mentioned the below. I have a question.

>1. Reading spi_RDR in debug window is potentially harmful: This is a
>hardware register where reading has side effects!

>2. While you are debugging SPI code, save those registers into a variable
>that you can safely read with the debugger."
   I had assigned the receive register to a variable. Even though it is 
not showing correct value. Please find the code below.

spi_read_status spi_read(Spi *p_spi,uint8_t *pcs, uint16_t *data)
{

  static uint32_t register_value;
  uint32_t timeout = SPI_READ_TIME_OUT;

  while (!(p_spi->SPI_SR & SPI_SR_RDRF)) {
    //if timer expires return timeout.
  }

  register_value = p_spi->SPI_RDR;
  if (spi_get_peripheral_select_mode(p_spi)) {
    //get the pcs value here from the spi_rdr
  }
  *data= (uint16_t) (register_value & SPI_RDR_Mask);

  return SPI_READ_OK;
}

Please clarify whether my understaning here is correct or not. Did you 
mean that I can't  debug and test in this way. Thank you.

: Edited by User
von fop (Guest)


Rate this post
useful
not useful
Begin with the simple faults :
Be sure to connect your osci directly at the microcontroller pin. So you 
can't be tricked by bad solder joints.
Verify that you use the right pin as MISO.
I never used JTAG on Atmels - is there no interference between Debugger 
and SPI ? I ask because programming is done via SPI pins on AVRs.

von Aditya K. (stadkama)


Rate this post
useful
not useful
fop wrote:

> I never used JTAG on Atmels - is there no interference between Debugger
> and SPI ? I ask because programming is done via SPI pins on AVRs.
 On atsam device there are only 2 interface to program/debug the micro 
controller i.e. jtag and swd. Is this reason why I am not able to see 
the proper values in the receive register during debugging?
 Because all other suggestions u had mentioned is working fine.

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.