SPI communication 4-20mA T click Transmitter

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

cross mob
User16901
Level 1
Level 1
Hi,

I am very new to Dave and microcontroller programming in General.

Has anyone ever combined a xmc with the 4-20mA T click Transmitter by mikroElektronika?

I want to use my XMC4300 microcontroller to control a 4-20mA current Loop. The 4-20mA T click communicates with the target board via three SPI lines.
In Dave, I found the SPI_MASTER app and example Code. I tried to set it up. My Goal is to, by sending different values via SPI, using the "SPI_MASTER_Transmit"-function, to change the current within the 4-20mA-loop. However, I am somehow unable to change the current.

I found Driver Code belonging to the Transmitter. Can anyone tell me if it is necassary to include this Code? Is it necassary to do slave configuration like in the SPI_MASTER app example?

I am sorry for the very stupid questions.

Regards!
0 Likes
5 Replies
User15886
Level 1
Level 1
What mode are you running the SPI channel - Direct, Interrupt or DMA? Do you see any of the 3 signals toggling on the board?
The example in the spi_master.h file shows a basic transfer using Direct mode with FIFO.
If you copy that and use the right values to talk to the transmitter it should work, but you have to make sure your baud rate (Bus Speed), word and frame length are correct for the part you are communicating to.

once you get the pins toggling, you can verify with a scope to make sure your timing is correct and adjust them with DAVE as necessary. With the receive FIFO enabled, you can also read back the response (if the part sends one), which might include some status info.
0 Likes
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

Just search for MCP49xx Arduino library and make a port of it using XMCLib or the API provided by SPI_MASTER APP.
Alternatively you can also use Arduino APIs on XMC, https://github.com/Infineon/XMC-for-Arduino

Regards,
Jesus
0 Likes
User16901
Level 1
Level 1
Thank you for your replies!

In the meanwhile, I often do have my desired current (4-20mA) in my current loop, however, I still have Problems with Controlling the current: Increasing the input value sometimes does increase the current as well, but then, it suddenly goes down again or sometimes, I don't get a signal at all. It seems to be very non-reconstructable. Do you have any ideas where this Problem could be caused? I really have not found a way yet to control my current properly.

How do I know which bus speed is correct?

I found this code where the 4-20mA Transmitter is connected to an Arduino. In this case, not only the message (12 Bit, as its a 12 bit DAC? ) is being sent, but also some bits in advance:

3555.attach

Do you know if setting these bits will be necassary in my case? I decided to send 1 word at the moment with the size of 16 bits, where I make sure that the first bits are set like in the Arduino example above:

master_send_data |= 0x3000;

As I said, I do get current flow doing it like this, but the current is not really controllable but rather "jumping" sometimes when only increasing the Input a little bit or so.

And if theres the possibility to include an Arduino library by making a port of it, @jferreira, could you go into a Little bit more Details on how to do that?

Thanks a lot!
0 Likes
User15886
Level 1
Level 1
I'd check to make sure you have setup to clock out the data on the falling edge of SCK, as the MCP4921 reads the data on the rising edge. Since it is working sometimes, it could be that you are violating the setup time by clocking out the data on the same edge as the DAC is reading it.
0 Likes
User16901
Level 1
Level 1
Thank you , this helped alot!
0 Likes