Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

DAVE™ Forum Discussions

Not applicable
Hello,

I am building a current sensing appliance. I am using XMC4500 application processor and TLI4970 current sensor. How should I set up the SPI Master App on XMC4500? I've already played around with it but I get no sensible data from the TLI4970.

I attached spi master app config:
1918.attach

I am using this code:


/*
* main.c
*
* Created on: 2016 Feb 24 17:50:15
* Author: Lukas Erlacher
*/




#include //Declarations from DAVE Code Generation (includes SFR declaration)
#include
#include

#include

union {
uint8_t spi_bytes[2];
uint16_t spi_word;
} spi_rx;

volatile uint16_t lmp[4] = {0xff};
volatile SPI_MASTER_STATUS_t sstatus = SPI_MASTER_STATUS_FAILURE;

int ct;
char line[17] = "________________";


void SpiReceive() {
sprintf(line, "%u", spi_rx.spi_word);
lcd_setcursor(0,1);
lcd_string(line);

ct++;
sprintf(line, "%d", ct);
lcd_setcursor(0,2);
lcd_string(line);
}

int main(void)
{
DAVE_STATUS_t status;
spi_rx.spi_word = 1;

status = DAVE_Init(); /* Initialization of DAVE APPs */

if(status == DAVE_STATUS_FAILURE)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}

lcd_init();
lcd_setcursor(0,1);

sprintf(line, "%u", spi_rx.spi_word);
lcd_string(line);

SPI_MASTER_DisableSlaveSelectSignal(&SPI_MASTER_0);
SPI_MASTER_EnableSlaveSelectSignal(&SPI_MASTER_0, SPI_MASTER_0.config->slave_select_pin_config[0]->slave_select_ch);

while(1U)
{
while(DIGITAL_IO_GetInput(&BTN_PUSH) == 0)
{

}
while(DIGITAL_IO_GetInput(&BTN_PUSH) == 1)
{

}

sstatus = SPI_MASTER_Receive(&SPI_MASTER_0, spi_rx.spi_bytes, 2);
}
}



The receive interrupt fires, but the returned value is always 65535.
0 Likes
8 Replies
Not applicable
HI,

From the code, the sequence of operation seems to be correct.
Can you share the project. The attachment you included in this thread does not have the project.

Regards,
Daryl
0 Likes
Not applicable
Hello,

I've attached my project. Thanks for looking into it!
0 Likes
Not applicable
It was actually a hardware problem - isolators for a second SPI Device on the bus that destroyed the signals.
0 Likes
Not applicable
Hi,

Great! 🙂 Glad that you managed to identify the issue. Hopefully your solution is now working!

Regards,
Daryl
0 Likes
User10076
Level 2
Level 2
Hello everyone,

I'm having some trouble reading TLI4970 current sensor. I'm trying just to get the data from the sensor in a controlled way. I'm using XMC1100 (XMC 2 go) and DAVE 4.2.6.
On the scope I'm seeing data beeing sent from the sensor, but I think I don't have the right sequence.

#include //Declarations from DAVE Code Generation (includes SFR declaration)

#define BUFFER_SIZE 2
uint8_t MasterReceivedData[BUFFER_SIZE];
SPI_MASTER_STATUS_t lstatus= SPI_MASTER_STATUS_FAILURE;
uint8_t count =0;


void SpiReceiveTli4970(void)
{
count++;
}

int main(void)
{
DAVE_STATUS_t status;

status = DAVE_Init(); /* Initialization of DAVE APPs */

if(status == DAVE_STATUS_FAILURE)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");

while(1U)
{

}
}

SPI_MASTER_DisableSlaveSelectSignal(&SPI_MASTER_0);
SPI_MASTER_EnableSlaveSelectSignal(&SPI_MASTER_0, SPI_MASTER_0.config->slave_select_pin_config[0]->slave_select_ch);

/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{
lstatus=SPI_MASTER_Receive(&SPI_MASTER_0,MasterReceivedData,BUFFER_SIZE);
}
}



The receive interrupt fires but as Lukas I'm getting only 255. 😞
Any hint would be appreciated.

Thank you,
Petru S.
0 Likes
Not applicable
- Don't use Disable/EnableSlaveSelectSignal, it's not needed
- Make sure you only have one slave select signal configured in the app, it doesn't work if there's more than one configured
- Enable frame end mode and set word length and frame length to 16
- Set Leading/Trailing delay to 2

The TLI component samples from the hall sensor when Slave Select is pulled low and needs the leading delay so it can prepare the SPI message. And Slave Select needs to go high after every message, this is accomplished by frame end mode.
0 Likes
User10076
Level 2
Level 2
Thank you lerlacher,

As expected it works quite reliably. However I don't quite get it when it send's a status message over a actual value message.
The raw values that I get are between 4096D (which correspond for the 0A, which is correct) and ~20101D (which I don't quite get from where it comes from).
Any hints would be appreciated.

Thank you!
Petru S.
0 Likes
jferreira
Employee
Employee
First like received 750 replies posted 500 replies posted
Hi,

In the data sheet it is stated the following:
The Sensor Status Word contains information about temperature and load conditions and is sent under the
following conditions:
• Once after start-up (“Sensor restarted”)
• During the sensor start-up phase when a command is sent (“Sensor busy”)
• If an internal error occurred (“Sensor fail”)

Normally after the startup, if the current is the measurement range, you should only get value messages.
Actually the 20101D = 0x4E85 has the bit 14 (parity bit) set

Regards,
Jesus
0 Likes