EmbeddedRelated.com
Forums

MSP430F449 SPI

Started by Jeyakumar October 12, 2007
Hi,

I wrote the code for SPI communication for MCP3551 ADC bellow. but it is not working. I always receive 0xFF in all arrays. Pls if any one correct me..

UCTL0 |= SWRST; // Initalize USART state machine
ME1 |= USPIE0; // Enable USART0 SPI mode
UCTL0 |= CHAR + SYNC + MM; // 8-bit SPI Master **SWRST**
UTCTL0 |= CKPL + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
//UTCTL0 |= CKPH + CKPL + SSEL0 + STC;
UBR00 = 0x04; // UCLK/2
UBR10 = 0x00; // 0
UMCTL0 = 0x00; // no modulation
UCTL0 &= ~SWRST; // Initalize USART state machine
P3SEL |= 0x0C; // P3.1-3 SPI option select
P3DIR |= 0x18;
P3DIR &= ~0x04; // P3.2 input direction
P3OUT &= ~0x10;

P3OUT &= ~0x10; //CS low
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[2] = RXBUF0;
for(int j=0xFFFF;j>0;j--);
for(int j=0xFFFF;j>0;j--);
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[1] = RXBUF0;
for(int j=0xFFFF;j>0;j--);
for(int j=0xFFFF;j>0;j--);
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[0] = RXBUF0;

P3OUT |= 0x10; //CS high

---------------------------------
Need a vacation? Get great deals to amazing places on Yahoo! Travel.

Beginning Microcontrollers with the MSP430

i'm not familiar with this ADC and a'm working still on assembler,
but Your code seems to be little bit wrong - see my suggestions
below. regards.

>
> UCTL0 |= SWRST; // Initalize USART
state machine
> ME1 |= USPIE0; // Enable USART0 SPI
mode

MOVE THIS DOWN - BEFORE BITCLEAR SWRST
> UCTL0 |= CHAR + SYNC + MM; // 8-bit SPI Master
**SWRST**
> UTCTL0 |= CKPL + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
> //UTCTL0 |= CKPH + CKPL + SSEL0 + STC;
> UBR00 = 0x04; // UCLK/2
> UBR10 = 0x00; // 0
> UMCTL0 = 0x00; // no modulation\

ALSO CHECHK OTHER SPI REGISTERS

> UCTL0 &= ~SWRST; // Initalize USART
state machine
> P3SEL |= 0x0C; // P3.1-3 SPI option
select
> P3DIR |= 0x18;
> P3DIR &= ~0x04; // P3.2 input
direction
> P3OUT &= ~0x10;
>
>
>
> P3OUT &= ~0x10; //CS low
> TXBUF0 = 0;
> do
> {
> IFG1 &=~ URXIFG0;
> }while (URXIFG0 & IFG1);
> Dummy[2] = RXBUF0;
> for(int j=0xFFFF;j>0;j--);
> for(int j=0xFFFF;j>0;j--);
mov #200,r15
WAGAIN1:
;this must not happen
;some timeout to not die
dec r15
jz stopwaitthis
BIT #UTXIFG0,IFG1
JZ WAGAIN1
stopwaitthis:

BIC.B #URXIFG0,IFG1
MOV.B #0,U0TXBUF
WAGAIN2:
BIT.B #URXIFG0,IFG1
JZ WAGAIN2
MOV.B U0RXBUF,Dummy+2 ;this will clear URXIFG0

> TXBUF0 = 0;
> do
> {
> IFG1 &=~ URXIFG0;
> }while (URXIFG0 & IFG1);
> Dummy[1] = RXBUF0;
> for(int j=0xFFFF;j>0;j--);
> for(int j=0xFFFF;j>0;j--);

MOV.B #0,U0TXBUF
WAGAIN21:
BIT.B #URXIFG0,IFG1
JZ WAGAIN21
MOV.B U0RXBUF,Dummy+1

> TXBUF0 = 0;
> do
> {
> IFG1 &=~ URXIFG0;
> }while (URXIFG0 & IFG1);
> Dummy[0] = RXBUF0;
MOV.B #0,U0TXBUF
WAGAIN22:
BIT.B #URXIFG0,IFG1
JZ WAGAIN22
MOV.B U0RXBUF,Dummy

>
> P3OUT |= 0x10; //CS high
>
>
Hi, After I check from the MCP3551 ADC data sheet it support for only SPI MODE 0 or 3. But for this line in your code, if I'm correct it's setting for MODE2.
UTCTL0 |= CKPL + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
The line you comment out is the setting for MODE3
Please try in MODE0 by set CKPL and CKPH to 0.
Another recommend please clear the register before use self OR instruction.
Think will help you.
Jeyakumar wrote: Hi,

I wrote the code for SPI communication for MCP3551 ADC bellow. but it is not working. I always receive 0xFF in all arrays. Pls if any one correct me..

UCTL0 |= SWRST; // Initalize USART state machine
ME1 |= USPIE0; // Enable USART0 SPI mode
UCTL0 |= CHAR + SYNC + MM; // 8-bit SPI Master **SWRST**
UTCTL0 |= CKPL + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
//UTCTL0 |= CKPH + CKPL + SSEL0 + STC;
UBR00 = 0x04; // UCLK/2
UBR10 = 0x00; // 0
UMCTL0 = 0x00; // no modulation
UCTL0 &= ~SWRST; // Initalize USART state machine
P3SEL |= 0x0C; // P3.1-3 SPI option select
P3DIR |= 0x18;
P3DIR &= ~0x04; // P3.2 input direction
P3OUT &= ~0x10;

P3OUT &= ~0x10; //CS low
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[2] = RXBUF0;
for(int j=0xFFFF;j>0;j--);
for(int j=0xFFFF;j>0;j--);
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[1] = RXBUF0;
for(int j=0xFFFF;j>0;j--);
for(int j=0xFFFF;j>0;j--);
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[0] = RXBUF0;

P3OUT |= 0x10; //CS high

---------------------------------
Need a vacation? Get great deals to amazing places on Yahoo! Travel.



---------------------------------
Shape Yahoo! in your own image. Join our Network Research Panel today!
Hi,
The clock should be starting from high to low ( from MCP3551 data sheet) . If I set CKPL and CKPH to 0, then the clock is come to low to high. I facing same problem again. I always getting 0xFF from the RXBUF0. Pls correct me..

bye
Pisit Sawangvonganan wrote:
Hi, After I check from the MCP3551 ADC data sheet it support for only SPI MODE 0 or 3. But for this line in your code, if I'm correct it's setting for MODE2.
UTCTL0 |= CKPL + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
The line you comment out is the setting for MODE3
Please try in MODE0 by set CKPL and CKPH to 0.
Another recommend please clear the register before use self OR instruction.
Think will help you.
Jeyakumar wrote: Hi,

I wrote the code for SPI communication for MCP3551 ADC bellow. but it is not working. I always receive 0xFF in all arrays. Pls if any one correct me..

UCTL0 |= SWRST; // Initalize USART state machine
ME1 |= USPIE0; // Enable USART0 SPI mode
UCTL0 |= CHAR + SYNC + MM; // 8-bit SPI Master **SWRST**
UTCTL0 |= CKPL + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
//UTCTL0 |= CKPH + CKPL + SSEL0 + STC;
UBR00 = 0x04; // UCLK/2
UBR10 = 0x00; // 0
UMCTL0 = 0x00; // no modulation
UCTL0 &= ~SWRST; // Initalize USART state machine
P3SEL |= 0x0C; // P3.1-3 SPI option select
P3DIR |= 0x18;
P3DIR &= ~0x04; // P3.2 input direction
P3OUT &= ~0x10;

P3OUT &= ~0x10; //CS low
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[2] = RXBUF0;
for(int j=0xFFFF;j>0;j--);
for(int j=0xFFFF;j>0;j--);
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[1] = RXBUF0;
for(int j=0xFFFF;j>0;j--);
for(int j=0xFFFF;j>0;j--);
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[0] = RXBUF0;

P3OUT |= 0x10; //CS high

---------------------------------
Need a vacation? Get great deals to amazing places on Yahoo! Travel.



---------------------------------
Shape Yahoo! in your own image. Join our Network Research Panel today!



---------------------------------
Be a better Globetrotter. Get better travel answers from someone who knows.
Yahoo! Answers - Check it out.
Hi, Jeyakumar

After I take a look in your source code here are the list that may be the source of problem
1) I think you should set MOSI pin for P3.1 too.
2) What's you MCLK speed 8 MHz? If yes, please lower your speed and after correct the problem then
go back to your desired MCLK speed.
3) You need to make a wait for ADC conversiton time after the falling edg of CS
It's take the time around 72.73 ms +- 1% Wait more than 100 ms to make sure for this point
4) CS state should be high in the idle state
5) Let's try the code that I modifie from your original code.

// Initialize Section
P3SEL = 0x00;
P3SEL |= 0x0E; // P3.1-3 SPI Option select
P3DIR |= 0x1A; // P3.1,3.3 Output direction, P3.4 use as CS
P3DIR &= ~0x04; // P3.2 Input direction
P3OUT |= 0x10; // Set CS to High First

UCTL0 = SWRST; // Initalize USART state machine
UCTL0 |= CHAR + SYNC + MM; // 8-bit SPI Master
UTCTL0 = 0x00;
UTCTL0 |= CKPH + CKPL + SSEL1 + SSEL0 + STC;
UBR00 = 0x04;
UBR10 = 0x00;
UMCTL0 = 0x00;
ME1 = 0x00;
ME1 |= USPIE0;
UCTL0 &= ~SWRST; // Initalize USART state machine
// Implement Section
P3OUT &= ~0x10; // CS low

// Add your delay here to make sure for more than 100 ms
// After the ADC conversion complete then you can read them
for(int j=0xFFFF;j>0; j--);
for(int j=0xFFFF;j>0; j--);

TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[2] = RXBUF0;

// For the consecutive read I think you can continue without delay
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[1] = RXBUF0;

TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[0] = RXBUF0;

P3OUT |= 0x10; //CS high
Jeyakumar wrote:
Hi,
The clock should be starting from high to low ( from MCP3551 data sheet) . If I set CKPL and CKPH to 0, then the clock is come to low to high. I facing same problem again. I always getting 0xFF from the RXBUF0. Pls correct me..

bye
Pisit Sawangvonganan wrote:
Hi, After I check from the MCP3551 ADC data sheet it support for only SPI MODE 0 or 3. But for this line in your code, if I'm correct it's setting for MODE2.
UTCTL0 |= CKPL + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
The line you comment out is the setting for MODE3
Please try in MODE0 by set CKPL and CKPH to 0.
Another recommend please clear the register before use self OR instruction.
Think will help you.
Jeyakumar wrote: Hi,

I wrote the code for SPI communication for MCP3551 ADC bellow. but it is not working. I always receive 0xFF in all arrays. Pls if any one correct me..

UCTL0 |= SWRST; // Initalize USART state machine
ME1 |= USPIE0; // Enable USART0 SPI mode
UCTL0 |= CHAR + SYNC + MM; // 8-bit SPI Master **SWRST**
UTCTL0 |= CKPL + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
//UTCTL0 |= CKPH + CKPL + SSEL0 + STC;
UBR00 = 0x04; // UCLK/2
UBR10 = 0x00; // 0
UMCTL0 = 0x00; // no modulation
UCTL0 &= ~SWRST; // Initalize USART state machine
P3SEL |= 0x0C; // P3.1-3 SPI option select
P3DIR |= 0x18;
P3DIR &= ~0x04; // P3.2 input direction
P3OUT &= ~0x10;

P3OUT &= ~0x10; //CS low
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[2] = RXBUF0;
for(int j=0xFFFF;j>0;j--);
for(int j=0xFFFF;j>0;j--);
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[1] = RXBUF0;
for(int j=0xFFFF;j>0;j--);
for(int j=0xFFFF;j>0;j--);
TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[0] = RXBUF0;

P3OUT |= 0x10; //CS high

---------------------------------
Need a vacation? Get great deals to amazing places on Yahoo! Travel.



---------------------------------
Shape Yahoo! in your own image. Join our Network Research Panel today!



---------------------------------
Be a better Globetrotter. Get better travel answers from someone who knows.
Yahoo! Answers - Check it out.



---------------------------------
Be a better Heartthrob. Get better relationship answers from someone who knows.
Yahoo! Answers - Check it out.
Is waiting for a self-clearing bit.

Best regards,
Adrian Popa

----- Original Message ----
From: stefandk63
To: m...
Sent: Monday, October 15, 2007 4:43:47 PM
Subject: [msp430] Re: MSP430F449 SPI

Hi,maybe i'm wrong,but

What exactly does this code?

TXBUF0 = 0;

do

{

IFG1 &=~ URXIFG0;

}while (URXIFG0 & IFG1);

Dummy[2] = RXBUF0;







____________________________________________________________________________________
Catch up on fall's hot new shows on Yahoo! TV. Watch previews, get listings, and more!
http://tv.yahoo.com/collections/3658
TXBUF0 = 0; ///start spi clock
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1); //wait for RX buffer to write
Dummy[2] = RXBUF0; //transfer the RX buffer data to a variable

stefandk63 wrote: Hi,maybe i'm wrong,but
What exactly does this code?

TXBUF0 = 0;
do
{
IFG1 &=~ URXIFG0;
}while (URXIFG0 & IFG1);
Dummy[2] = RXBUF0;

---------------------------------
Catch up on fall's hot new shows on Yahoo! TV. Watch previews, get listings, and more!