EmbeddedRelated.com
Forums
Memfault Beyond the Launch

LPC2194 Getting started

Started by Max00007 February 14, 2008
Hi everyone,

I´m student and everything about embedded systems & my LPC is completley
new for me.(I am using an LPC 2194 with ECO-arm / WIN-arm compiler.)
I´ve got some programming experience but it seems: not enough. (VBA=
rather good; C= total beginner). So I would also appreciate every hint to
good tutorials and other help.

Besides these probs the most urgent is: Getting the SPI to work (in
general) and with a ADIS16350 (Gyro)Sensor. I´ve worked my my through the
common examples (and most of them worked) but I´m not getting the real
thing to work. This is how far I´ve come. I know it´s not much but even
a "throw it all away" helps ;-). Thanks!

static void
spi_init(void)
{
	Intern_pinsel0 |= 0x1500;		// enable SPI pins
	Intern_spcr     = 0x20;			// set master mode
	Intern_spccr    = 8;			// SCK =pclk/10
}

int main(void)
{
 while (1) 
 {
  spi_init();
  dtareg = S0SPDR;
  printf("%i\n", dtareg);
  delay(250);
 }
 putchar('\n');
 if (errno&0x08) puts("--ERROR: Slave abort");
 if (errno&0x10) puts("--ERROR: Mode fault");
 if (errno&0x20) puts("--ERROR: Read overrun");
 if (errno&0x40) puts("--ERROR: Write collision");
 abort();
}




On Thu, 14 Feb 2008 09:44:19 -0600, "Max00007" <pain00007@gmx.de>
wrote:

>Hi everyone, > >I&acute;m student and everything about embedded systems & my LPC is completley >new for me.(I am using an LPC 2194 with ECO-arm / WIN-arm compiler.) >I&acute;ve got some programming experience but it seems: not enough. (VBA= >rather good; C= total beginner). So I would also appreciate every hint to >good tutorials and other help. > >Besides these probs the most urgent is: Getting the SPI to work (in >general) and with a ADIS16350 (Gyro)Sensor. I&acute;ve worked my my through the >common examples (and most of them worked) but I&acute;m not getting the real >thing to work. This is how far I&acute;ve come. I know it&acute;s not much but even >a "throw it all away" helps ;-). Thanks! > >static void >spi_init(void) >{ > Intern_pinsel0 |= 0x1500; // enable SPI pins > Intern_spcr = 0x20; // set master mode > Intern_spccr = 8; // SCK =pclk/10 >} > >int main(void) >{ > while (1) > { > spi_init(); > dtareg = S0SPDR; > printf("%i\n", dtareg); > delay(250); > }
[some code snipped] You are re-initialising the SPI peripheral every time in your loop. You should only have to initialise the peripheral once. Also SPI clocks data in at the same time data is being clocked out. So you have to write some value to the SPI data register, which will then clock this value out, and simultaneously clock a value in. You should poll the status register after you have written to the data register to check when the SPI transaction has completed. Regards Anton Erasmus
Thank&acute;s for the help. :-)
I tried with little success until I found out, that I&acute;ve got a much
bigger problem. 

If im right the the SPI register on the LPC has only 8bits?
But the sensor transmits 14 bits per axis meaning I&acute;ve got 42 bit (or
maybe even 84 bit) to handle. Now I already figured out, that I have to
replace the SCLK pin by a normal GPIO pin in order to get a "manual"
clocking.
While I did that it became clear, that I can read the content of the
registers but sending the right content in the correct form to the sensor
and getting the timing done manually?

Honestley: I&acute;ve got no idea what to do.

Again: Thanks for the help :-)
"Max00007" <pain00007@gmx.de> wrote in message 
news:itGdnVTKLrREOijanZ2dnUVZ_ournZ2d@giganews.com...
> Thank&acute;s for the help. :-) > I tried with little success until I found out, that I&acute;ve got a much > bigger problem. > > If im right the the SPI register on the LPC has only 8bits? > But the sensor transmits 14 bits per axis meaning I&acute;ve got 42 bit (or > maybe even 84 bit) to handle. Now I already figured out, that I have to > replace the SCLK pin by a normal GPIO pin in order to get a "manual" > clocking. > While I did that it became clear, that I can read the content of the > registers but sending the right content in the correct form to the sensor > and getting the timing done manually? > > Honestley: I&acute;ve got no idea what to do. > > Again: Thanks for the help :-)
The manual clocking approach should probably work unless your sensor has particular limits on the low end of timing, but that is unlikely. As Anton wrote, SPI sends and receives data at the same time. You need to check the sensor spec and find out what command or command sequence it needs. Often the spec is to send a command byte/word followed by a NULL or dummy value. It responds to the command during reception of the dummy value. The number of bits is determined by the device. In your case it seems to be 14. Scott
"Max00007" <pain00007@gmx.de> wrote in message 
news:itGdnVTKLrREOijanZ2dnUVZ_ournZ2d@giganews.com...
> Thank&acute;s for the help. :-) > I tried with little success until I found out, that I&acute;ve got a much > bigger problem. > > If im right the the SPI register on the LPC has only 8bits? > But the sensor transmits 14 bits per axis meaning I&acute;ve got 42 bit (or > maybe even 84 bit) to handle. Now I already figured out, that I have to > replace the SCLK pin by a normal GPIO pin in order to get a "manual" > clocking. > While I did that it became clear, that I can read the content of the > registers but sending the right content in the correct form to the sensor > and getting the timing done manually? > > Honestley: I&acute;ve got no idea what to do. > > Again: Thanks for the help :-)
I think your thinking of what you can do with the interface is too restrictive. As Anton pointed out in his post (prior to this message) to read data in, you have to clock data out (even if the data transmitted is ignored by the other device). The point here is that to generate clocks you have to put data into the Tx FIFO. If you want to read more data then send more data (put more data in the Tx FIFO). You aren't stuck with a single transfer per SPI transaction. I think the NXP specifications use the term "frame" for what I am calling a "transfer". A transaction can be multiple transfers in length. This same prinicpal lets you composite transatactions made of of multiple sub-fields (address, command, data) where each field is of differnt lengths. For example, 24-bits of address, 8-bits of command, 32-bits of data. TC
I think i&acute;ve got the point now. Thanks everyone :-)!
I&acute;ve just tried some basic things and it seems to work. 
Now i just need to figure out what command my sensor needs to start
sending data.
Thanks again for the help.

On Feb 15, 3:55 pm, "Max00007" <pain00...@gmx.de> wrote:
> Thank=B4s for the help. :-) > I tried with little success until I found out, that I=B4ve got a much > bigger problem. > > If im right the the SPI register on the LPC has only 8bits? > But the sensor transmits 14 bits per axis meaning I=B4ve got 42 bit (or > maybe even 84 bit) to handle. Now I already figured out, that I have to > replace the SCLK pin by a normal GPIO pin in order to get a "manual" > clocking. > While I did that it became clear, that I can read the content of the > registers but sending the right content in the correct form to the sensor > and getting the timing done manually? > > Honestley: I=B4ve got no idea what to do. > > Again: Thanks for the help :-)
Hi, can you please check whether you have a LPC2194 or a LPC2194/01? If it is the latter, the SPI can actually receive data with a flexible length up to 16-bit. The /01 type has been on the market for a few months now and fixes most Erratas of the CAN as well as introduces upgrades for some functionalities like the SPI. The improved version is called SSP. I found a new Users Manual here: http://www.lpc2000.com/ If it is the older version, you can still use the SPI but need to make sure that you have back to back receive operation. As this interface is triggered by a clock, it should still be possible to use two receive operations with 8-bit rather than bit-banging this function. LC

Memfault Beyond the Launch