Forums

Problem with SPI1 on LPC2119

Started by irafalovsky August 8, 2006
I wonder if anyone can help me with the problem we are having with
interfacing a peripheral to LPC2119...

The issue is that a peripheral (MicroMag 3 from PNI Corp) expects 8
bit command and after measurement transmits 16 bit of data back to
master.

We have set up LPC2119 in SPI1 master mode, transmit 8 bit command to
Micromag 3 and read S1SPDR twice after peripheral signals the end of
measurement, however results we're getting are pretty much garbage...

I wonder if anyone has tried receiving multi-byte results from SPI
peripherals and if there are any quirks there...

With kind regards,

Igor Rafalovsky
R3 Scientific Corp

An Engineer's Guide to the LPC2100 Series

--- In l..., "irafalovsky" wrote:
>
> I wonder if anyone can help me with the problem we are having with
> interfacing a peripheral to LPC2119...
>
> The issue is that a peripheral (MicroMag 3 from PNI Corp) expects 8
> bit command and after measurement transmits 16 bit of data back to
> master.
>
> We have set up LPC2119 in SPI1 master mode, transmit 8 bit command to
> Micromag 3 and read S1SPDR twice after peripheral signals the end of
> measurement, however results we're getting are pretty much garbage...
>
> I wonder if anyone has tried receiving multi-byte results from SPI
> peripherals and if there are any quirks there...
>
> With kind regards,
>
> Igor Rafalovsky
> R3 Scientific Corp
>

Do you send 2 bytes out from LPC2119 to allow the SPI clock to go so
you can get back the 2 bytes that you are expecting?

We have an application with LPC2138 running in slave mode and
receiving packets of 9 bits characters from an host processor and
responding with packets of 9 bits characters.
Naturally, in order to be able to send back the answer the LPC must
receive the spi clock from the master so the host processor must pump
out dummy characters to allow the answer to come back.

Regards,

Carlo Barbaro
If we attempt to send 2 bytes after peripheral indicates available
data, we simply get zeroes in return...

Here's what code looks like:

IOSET0 |= 1 << 23; // Set RESET HIGH, this is to reset the MM3
delay(10);
IOCLR0 |= 1 << 23; // Set RESET LOW, pulse formed
delay(10);
S1SPDR = 0x41; // Send Measure X command
while((S1SPSR & 0x80)!= 0x80){;;} // Wait for SPI status
while(!(IOPIN0 && (1 << 22))){;;} // Wait for Data Ready
S1SPDR = 0;
S1SPDR = 0;
MM3_HB = S1SPDR;
MM3_LB = S1SPDR;
wMM3_X = MM3_HB;
wMM3_X = (wMM3_X << 8) | MM3_LB;
>
> Do you send 2 bytes out from LPC2119 to allow the SPI clock to go so
> you can get back the 2 bytes that you are expecting?
>
> We have an application with LPC2138 running in slave mode and
> receiving packets of 9 bits characters from an host processor and
> responding with packets of 9 bits characters.
> Naturally, in order to be able to send back the answer the LPC must
> receive the spi clock from the master so the host processor must pump
> out dummy characters to allow the answer to come back.
>
> Regards,
>
> Carlo Barbaro
>
Hi,

> If we attempt to send 2 bytes after peripheral indicates
> available data, we simply get zeroes in return...
>
> Here's what code looks like:
>
> IOSET0 |= 1 << 23; // Set RESET HIGH, this is to reset the MM3
> delay(10);
> IOCLR0 |= 1 << 23; // Set RESET LOW, pulse formed
> delay(10);
> S1SPDR = 0x41; // Send Measure X command
> while((S1SPSR & 0x80)!= 0x80){;;} // Wait for SPI status
> while(!(IOPIN0 && (1 << 22))){;;} // Wait for Data Ready
> S1SPDR = 0;
> S1SPDR = 0;
> MM3_HB = S1SPDR;
> MM3_LB = S1SPDR;
> wMM3_X = MM3_HB;
> wMM3_X = (wMM3_X << 8) | MM3_LB;

Oh my god. Read the data sheet, please, read the data sheet. Don't
bother until you've read the data sheet. The error is obvious here.

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
I apologize if you got offended somehow, but we did read the
datasheet and the manual very carefully. Needless to say, there is
no useful information on the topic in both documents and this is the
reason I asked the question here...

If the error is obvious, could you please kindly point me to it?

With best regards,

Igor.

>
> Hi,
>
> > If we attempt to send 2 bytes after peripheral indicates
> > available data, we simply get zeroes in return...
> >
> > Here's what code looks like:
> >
> > IOSET0 |= 1 << 23; // Set RESET HIGH, this is to reset the MM3
> > delay(10);
> > IOCLR0 |= 1 << 23; // Set RESET LOW, pulse formed
> > delay(10);
> > S1SPDR = 0x41; // Send Measure X command
> > while((S1SPSR & 0x80)!= 0x80){;;} // Wait for SPI status
> > while(!(IOPIN0 && (1 << 22))){;;} // Wait for Data Ready
> > S1SPDR = 0;
> > S1SPDR = 0;
> > MM3_HB = S1SPDR;
> > MM3_LB = S1SPDR;
> > wMM3_X = MM3_HB;
> > wMM3_X = (wMM3_X << 8) | MM3_LB;
>
> Oh my god. Read the data sheet, please, read the data sheet.
Don't
> bother until you've read the data sheet. The error is obvious
here.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
>
Shouldn't these be interlaced:

> > S1SPDR = 0;
> > S1SPDR = 0;
> > MM3_HB = S1SPDR;
> > MM3_LB = S1SPDR;

Should be:

> > S1SPDR = 0;
> > MM3_HB = S1SPDR;
> > S1SPDR = 0;
> > MM3_LB = S1SPDR;

Otherwise, you wipe out the first value in S1SPDR before you
read it.

MX
-----Original Message-----
From: l... [mailto:l...]On Behalf Of irafalovsky
Sent: Tuesday, August 08, 2006 2:37 PM
To: l...
Subject: [lpc2000] Re: Problem with SPI1 on LPC2119
I apologize if you got offended somehow, but we did read the
datasheet and the manual very carefully. Needless to say, there is
no useful information on the topic in both documents and this is the
reason I asked the question here...

If the error is obvious, could you please kindly point me to it?

With best regards,

Igor.

>
> Hi,
>
> > If we attempt to send 2 bytes after peripheral indicates
> > available data, we simply get zeroes in return...
> >
> > Here's what code looks like:
> >
> > IOSET0 |= 1 << 23; // Set RESET HIGH, this is to reset the MM3
> > delay(10);
> > IOCLR0 |= 1 << 23; // Set RESET LOW, pulse formed
> > delay(10);
> > S1SPDR = 0x41; // Send Measure X command
> > while((S1SPSR & 0x80)!= 0x80){;;} // Wait for SPI status
> > while(!(IOPIN0 && (1 << 22))){;;} // Wait for Data Ready
> > S1SPDR = 0;
> > S1SPDR = 0;
> > MM3_HB = S1SPDR;
> > MM3_LB = S1SPDR;
> > wMM3_X = MM3_HB;
> > wMM3_X = (wMM3_X << 8) | MM3_LB;
>
> Oh my god. Read the data sheet, please, read the data sheet.
Don't
> bother until you've read the data sheet. The error is obvious
here.
>
> --
> Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
>
We first attempted reading two bytes in succession without any
additional writes, which is how Philips demonstrates it in one of
their Application Notes.

That attempt produces really erratic results, after which we
attempted what you suggested second and are getting zero values for
both reads.

The example code showed implementation of a suggestion made by
c.barbaro in an earlier post (regarding sending two bytes to keep
SCLK moving). This code also produces zero values.

>
> Shouldn't these be interlaced:
>
> > > S1SPDR = 0;
> > > S1SPDR = 0;
> > > MM3_HB = S1SPDR;
> > > MM3_LB = S1SPDR;
>
> Should be:
>
> > > S1SPDR = 0;
> > > MM3_HB = S1SPDR;
> > > S1SPDR = 0;
> > > MM3_LB = S1SPDR;
>
> Otherwise, you wipe out the first value in S1SPDR before you
> read it.
>
> MX
> -----Original Message-----
> From: l... [mailto:l...]On
Behalf Of irafalovsky
> Sent: Tuesday, August 08, 2006 2:37 PM
> To: l...
> Subject: [lpc2000] Re: Problem with SPI1 on LPC2119
> I apologize if you got offended somehow, but we did read the
> datasheet and the manual very carefully. Needless to say, there is
> no useful information on the topic in both documents and this is
the
> reason I asked the question here...
>
> If the error is obvious, could you please kindly point me to it?
>
> With best regards,
>
> Igor.
>
> >
> > Hi,
> >
> > > If we attempt to send 2 bytes after peripheral indicates
> > > available data, we simply get zeroes in return...
> > >
> > > Here's what code looks like:
> > >
> > > IOSET0 |= 1 << 23; // Set RESET HIGH, this is to reset the MM3
> > > delay(10);
> > > IOCLR0 |= 1 << 23; // Set RESET LOW, pulse formed
> > > delay(10);
> > > S1SPDR = 0x41; // Send Measure X command
> > > while((S1SPSR & 0x80)!= 0x80){;;} // Wait for SPI status
> > > while(!(IOPIN0 && (1 << 22))){;;} // Wait for Data Ready
> > > S1SPDR = 0;
> > > S1SPDR = 0;
> > > MM3_HB = S1SPDR;
> > > MM3_LB = S1SPDR;
> > > wMM3_X = MM3_HB;
> > > wMM3_X = (wMM3_X << 8) | MM3_LB;
> >
> > Oh my god. Read the data sheet, please, read the data sheet.
> Don't
> > bother until you've read the data sheet. The error is obvious
> here.
> >
> > --
> > Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> > CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3
processors
>
Also, I don't see it doing a chip select, unless it's
outside the range of code you show.

MX

-----Original Message-----
From: l... [mailto:l...]On Behalf Of irafalovsky
Sent: Tuesday, August 08, 2006 2:52 PM
To: l...
Subject: [lpc2000] Re: Problem with SPI1 on LPC2119
We first attempted reading two bytes in succession without any
additional writes, which is how Philips demonstrates it in one of
their Application Notes.

That attempt produces really erratic results, after which we
attempted what you suggested second and are getting zero values for
both reads.

The example code showed implementation of a suggestion made by
c.barbaro in an earlier post (regarding sending two bytes to keep
SCLK moving). This code also produces zero values.

>
> Shouldn't these be interlaced:
>
> > > S1SPDR = 0;
> > > S1SPDR = 0;
> > > MM3_HB = S1SPDR;
> > > MM3_LB = S1SPDR;
>
> Should be:
>
> > > S1SPDR = 0;
> > > MM3_HB = S1SPDR;
> > > S1SPDR = 0;
> > > MM3_LB = S1SPDR;
>
> Otherwise, you wipe out the first value in S1SPDR before you
> read it.
>
> MX
> -----Original Message-----
> From: l... [mailto:l...]On
Behalf Of irafalovsky
> Sent: Tuesday, August 08, 2006 2:37 PM
> To: l...
> Subject: [lpc2000] Re: Problem with SPI1 on LPC2119
> I apologize if you got offended somehow, but we did read the
> datasheet and the manual very carefully. Needless to say, there is
> no useful information on the topic in both documents and this is
the
> reason I asked the question here...
>
> If the error is obvious, could you please kindly point me to it?
>
> With best regards,
>
> Igor.
>
> >
> > Hi,
> >
> > > If we attempt to send 2 bytes after peripheral indicates
> > > available data, we simply get zeroes in return...
> > >
> > > Here's what code looks like:
> > >
> > > IOSET0 |= 1 << 23; // Set RESET HIGH, this is to reset the MM3
> > > delay(10);
> > > IOCLR0 |= 1 << 23; // Set RESET LOW, pulse formed
> > > delay(10);
> > > S1SPDR = 0x41; // Send Measure X command
> > > while((S1SPSR & 0x80)!= 0x80){;;} // Wait for SPI status
> > > while(!(IOPIN0 && (1 << 22))){;;} // Wait for Data Ready
> > > S1SPDR = 0;
> > > S1SPDR = 0;
> > > MM3_HB = S1SPDR;
> > > MM3_LB = S1SPDR;
> > > wMM3_X = MM3_HB;
> > > wMM3_X = (wMM3_X << 8) | MM3_LB;
> >
> > Oh my god. Read the data sheet, please, read the data sheet.
> Don't
> > bother until you've read the data sheet. The error is obvious
> here.
> >
> > --
> > Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> > CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3
processors
>
--- In l..., "Woolsey Matt"
wrote:
>
> Also, I don't see it doing a chip select, unless it's
> outside the range of code you show.
>
> MX

Yes, it is outside, I didn't want to bother audience with the code
that works... :-)
How about waiting for some data to come back for a start?

--
Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors

> -----Original Message-----
> From: irafalovsky [mailto:r...@ivr.org]
> Sent: 08 August 2006 22:37
> To: l...
> Subject: [lpc2000] Re: Problem with SPI1 on LPC2119
>
> I apologize if you got offended somehow, but we did read the
> datasheet and the manual very carefully. Needless to say,
> there is no useful information on the topic in both documents
> and this is the reason I asked the question here...
>
> If the error is obvious, could you please kindly point me to it?
>
> With best regards,
>
> Igor.
>
> >
> > Hi,
> >
> > > If we attempt to send 2 bytes after peripheral indicates
> available
> > > data, we simply get zeroes in return...
> > >
> > > Here's what code looks like:
> > >
> > > IOSET0 |= 1 << 23; // Set RESET HIGH, this is to reset the MM3
> > > delay(10);
> > > IOCLR0 |= 1 << 23; // Set RESET LOW, pulse formed
> > > delay(10);
> > > S1SPDR = 0x41; // Send Measure X command
> > > while((S1SPSR & 0x80)!= 0x80){;;} // Wait for SPI status
> > > while(!(IOPIN0 && (1 << 22))){;;} // Wait for Data Ready
> > > S1SPDR = 0;
> > > S1SPDR = 0;
> > > MM3_HB = S1SPDR;
> > > MM3_LB = S1SPDR;
> > > wMM3_X = MM3_HB;
> > > wMM3_X = (wMM3_X << 8) | MM3_LB;
> >
> > Oh my god. Read the data sheet, please, read the data sheet.
> Don't
> > bother until you've read the data sheet. The error is obvious
> here.
> >
> > --
> > Paul Curtis, Rowley Associates Ltd http://www.rowley.co.uk
> > CrossWorks for ARM, MSP430, AVR, MAXQ, and now Cortex-M3 processors
> >
>
>