Interfacing The LDC1000 With Arduino
Interfacing The LDC1000 With Arduino
Pelonomi Moiloa
University of Witwatersrand
School of Electrical Engineering
30 June 2014
Contents
1 Introduction 2
3 SPI 2
4 Hardware 2
4.1 Pin Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
5 Software 3
5.1 LDC1000 software overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
5.2 Setting up an external clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
5.3 SPI communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
5.3.1 Communication Check: Reading register defaults . . . . . . . . . . . . . . . . . 5
5.3.2 Reading proximity registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
5.3.3 Reading Both Proximity and Frequency data Registers . . . . . . . . . . . . . . 6
1
1 Introduction
This document details the process of interfacing the LDC1000 with micro-controller Arduino (obtaining
proximity and frequency data). Both Arduino Uno and Arduino Mega2560s are used.
3 SPI
The LDC1000 communicates with an Arduino using SPI communication. The Arduino acts as the
master and the LDC1000 as the slave. At this point the master(Arduino)only communicates with a
single slave(LDC1000)but it is possible for the master to communicate with many slaves. A slave is
¯ in Figure 1.)in some way specified by the
selected by the master by changing the Chip Select Bit (SS
slaves data sheet.
4 Hardware
The hardware components include: an LDC1000 chip with its provided inductor coil sensor connected
to the INA and INB pins; An arduino (either an Uno or an Atmega) and an external clock (explained
a little later).
The LDC1000 is connected to the Arduino according to Table 1 and Table 2 for SPI communica-
tion. These connections can be confirmed with the LDC1000 and Arduino data sheets. (NB: Arduino
chip pins numbers do not correspond to numbers found on the Arduino board)
Note: Both ground pins of the LDC1000 must be connected to a common ground for communications
to be successful.
2
Table 1: LDC1000 Hardware set up top
Slave Master LDC1000 Arduino Uno pin Arduino Mega2560 pin Other
5V 5V 5V
LDCLK External Clock
SCLK SCLK SCLK 13 52
SD1 MOSI SD1 11 51
Vio 3.3 V 3.3 V
Slave Master LDC1000 Arduino Uno pin Arduino Mega2560 pin Other
GND Ground Ground
INT
CSB CSB CSB 10 53
SD0 MISO SD0 12 50
GND Ground Ground
Pin Description
LDCLK Pin connection for the external clock
SCLK internal SPI clock
SD1/MOSI master out slave in (information sent from master to slave)
INT interrupt pin
CSB chip select bit
SD0/MISO master in slave out (information sent from slave received by master)
5 Software
Code is implemented to read registers of the LDC1000 and code is also written to set up an external
clock. Refer to arduino.ino files for code for sections 5.2 to 5.3.
(a) The CSB line going to the slave is at a default HI, it is pulled LOW to initiate conversation
between the master and the slave
(b) The CSB line must be deasserted (returned to default) after the 16th clock (of SCLK) or
otherwise at every 8 ∗ (N + 1) clock cycle, for data is written into the LDC1000 registers
on the rising edge of the sixteenth clock (SEE: Extended SPI Transactions in the LDC1000
data sheet )
3
3. Data is sent from the Arduino to the LDC1000 in byte form MSB first, 16 bits at a time over
16 clocks
(a) The first byte holds a read(MSB = 1)/write(MSB = 0) instruction in its most significant
bit and the register address in question in the remaining 7 bits.
(b) The second byte is either 0x00 to receive information to be stored or it is the variable the
user wishes to store in that register
• The OC2A (PWM output pin) shares the same pins used in SPI communication for the Arduino
Uno thus an additional Arduino would have to serve the function of the external clock.
Table 4: Timer2 Control Registers of both Arduino Mega2560 and Arduino Uno
4
c o n s t i n t pwm8 = 1 0 ;
void setup ( ) {
// i n i t i a l i z e t h e d i g i t a l p i n a s an output .
pinMode (pwm8, OUTPUT) ;
TCCR2A = ((1<<WGM21) | (1<<COM2A0 ) ) ;
// s e t WGM t o CTC mode and e n a b l e output A
TCCR2B = ( 1 << CS20 ) ; / / s e t p r e s c a l e r t o 1
TIMSK2 = 0 ; / / d i s a b l e t i m e r i n t e r r u p t j u s t i n c a s e
}
void loop ( ) {
S e r i a l . begin (9600);
}
• OC2A: PWM Timer2 output for Arduino Uno = pin 11/ Mega = pin 10
• CS := 001 technically we want clk/2 but by trial and error clk/1 gives us 8MHz
Arduino source code seen in Figure 4. The resulting value of the example provided should be 0x1B.
Note:
• The PWR MODE must be set to 0 to configure register values and brought back up to 1 after
the value/s have been initialized to allow for reading of proximity data.
5
• Sensor frequency, LDC configuration and CLK configuration are configured only when it is
required to read frequency data
Table 5: LDC1000 Register Configuration
• Clock output connected to LDCLK/TBCLK (from pin 10 if Arduino Mega is used) and ground
of clock must e connected to ground of LDC1000/Arduino Master
• LDC configuration sets amplitude and frequency to 384 and 6144 respectively
• CLK configuration is set to external clock (in comparison to crystal) used and LDCLK/TBCLK
(external time based clock) enabled.
6
#i n c l u d e ” SPI . h” // i n c l u d e a r d u i n o SPI l i b r a r y
void setup ( )
{
S e r i a l . begin (9600);
// s t a r t SPI l i b r a r y / a c t i v a t e BUS
SPI . b e g i n ( ) ;
void loop ( )
{
unsigned i n t val = 0 ;
byte READ = 0 x80 ; // MSB = 1 which i s a ’ read ’ b i t
byte r e g = 0 x04 ; // r e g i s t e r a d d r e s s
SPI . s e t B i t O r d e r (MSBFIRST ) ;
// CPOL = 0 and CPH = 0 mode 3 a l s o works
SPI . setDataMode (SPI MODE0 ) ;
// s e t SCLK @ 4MHz, LDC1000 max i s 4MHz DIV2 a l s o works
SPI . s e t C l o c k D i v i d e r ( SPI CLOCK DIV4 ) ;
// b e g i n data t r a n s f e r
d i g i t a l W r i t e (CSB, LOW) ;
// MSB = r e a d b i t , r e m a i n i n g 7 b i t s i s r e g i s t e r a d d r e s s
byte d a t a 2 s e n d = READ + r e g ;
SPI . t r a n s f e r ( d a t a 2 s e n d ) ;
// send 0 x00 t o s i g n i f y a r e a d / s t o r e o f next 8 b i t s
v a l = SPI . t r a n s f e r ( 0 x00 ) ;
// p r i n t s 8 b i t d e c i m a l r e g i s t e r v a l u e
S e r i a l . println ( val ) ;
// end data t r a n s f e r
d i g i t a l W r i t e (CSB, HIGH ) ;
delay (500 );