Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SPI interfac external DAC

Status
Not open for further replies.

amyle

Newbie level 3
Newbie level 3
Joined
Aug 27, 2007
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
msp430f1611 spi

Hi everyone,

I'm trying to interface an external ADC with the MSP430F1611's SPI.

I've written the code to initialize the SPI (seen below), but I now want to test my Init_SPI by writing some data to it and probing it using the scope to see that I've written data to it.

Eventually, I want to get data from an external ADC using SPI and store it in memory.

Can anyone point me in the right direction?

Thank you so much! Much appreciated.

- Amy


====================INIT_SPI=========================

void Init_SPI(void)
{
P3SEL |= 0x3F; // Select P3.0,1,2,3,4,5
P3DIR |= 0x0B; // Select P3.1,3 as output directions
P3OUT &= ~0x01;
ME1 |= USPIE0; // ENABLE USART0 SPI
UCTL0 |= CHAR + SYNC + MM; // 8-bit data, SPI mode
UTCTL0 |= CKPH + CKPL + SSEL1; // Inv.delay, ACLK
UBR00 = 0x2A; // Baud Rate = 115200
UBR10 = 0x0;
UMCTL0 = 0x0; // Clear Modulation
UCTL0 &= ~SWRST; // Initialize USART state machine

//_BIS_SR(LPM3_bits + GIE); // Enter LPM0 w/interrupt

} //end Init_SPI

===============================================
 

It's simple. I suppose you use IAR. In init function put

IE1|=UTXIE0 | URXIE0;
__enable_interrupts();

I give you some indications about to write a data buffer of fixed size:

declare a global scope variable volatile short sizetx
declare a global scope char array (buffertx)
declare a global scope pointer to char (pointertx)

prepare the buffertx
set sizetx variable (the number of byte to transmit)
set pointertx equal to buffertx
to start tx write in U0TXBUF register the first data byte (buffertx[0])

write the tx interrupt handler
#pragma vector = USART0TX_VECTOR
void TxInt(void)
{
if(--sizetx)
{
U0TXBUF =*(++pointer);
}
}

to rx data:
#pragma vector = USART0RX_VECTOR
void RxInt(void)
{
if(sizerx)
{
*pointerrx=U0RXBUF;
pointerrx++;
sizerx--;
}
}

When you want to enable rx simply set sizerx to the number of byte that are expected and pointerrx to make it point to destination buffer. pointerrx and sizerx must be declared volatile.

This helps you ?

SimNav
 

Hi SimNav,

Thanks for the reply.

I'm still quite confused how I can receive data from my external ADC78H90 (slave) because that ADC needs a specific protocol to send me its data.

Note that for my project, the uC SPI is the master, and the external ADC is the slave. So the SPI and ADC pin configurations are:

Master: Slave:
-----------------------
STE -------> SCB
SCLK------> UCLK
Dout ------> SOMI
Din <------- SOMI


Now, for the external ADC to send me its data, I need to do the following:
1) Set SCB low
2) Set UCLK
3) Send the ADC an address
4) Get ADC output and store in SPI buffer, then store data in RAM.


So, I guess my confusion is, I don't even know how to get the external ADC talking to my MSP430F1611 SPI.

It seems like I can get my external ADC to talk to the uC using bit banging from the GPIO, but the SPI is there for a purpose and I want to use it. But I don't even know how to set SCB low.

Any take on that? Thanks.

- Amy
 

See figure 1 in the ADC78H90 datasheet.

The uC has to provide 16 SCLK pulses to the ADC for it to shift its data out.
This is done by writing a 16-bit word or two bytes from the MSP430F1611 to
the ADC (DIN). I'm not familiar with the uC so I don't know if it can write 16 bits at
a time. Often one can set the SPI port in various modes.

Three of the bits are the address bits that select which mux input to read.
The rest are dummy bits (DON'T CARE).

The CS signal has to be set low for the ADC to respond. If it is the only SPI
device on the bus, it can be tied to ground permanently.

So, when you have written the 16 bits the 12-bit data from the ADC will be
automaticaly transfered to the SPI input register. It's that simple.

Start by writing 0000h to the ADC to read AIN1. When that works you can
start changing the address bits to read other inputs.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top