EmbDev.net

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


von Aditya K. (stadkama)


Attached files:

Rate this post
0 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
0 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
0 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
0 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
0 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.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.