LPC2194 Getting started

Hi everyone,

I´m student and everything about embedded systems & my LPC is completle 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 t good tutorials and other help.

Besides these probs the most urgent is: Getting the SPI to work (i general) and with a ADIS16350 (Gyro)Sensor. I´ve worked my my through th common examples (and most of them worked) but I´m not getting the rea thing to work. This is how far I´ve come. I know it´s not much but eve 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(); }

Reply to
Max00007
Loading thread data ...

[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

Reply to
Anton Erasmus

Thank´s for the help. :-) I tried with little success until I found out, that I´ve got a muc 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´ve got 42 bit (o maybe even 84 bit) to handle. Now I already figured out, that I have t 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 th registers but sending the right content in the correct form to the senso and getting the timing done manually?

Honestley: I´ve got no idea what to do.

Again: Thanks for the help :-)

Reply to
Max00007

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

Reply to
Not Really Me

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

Reply to
TC

I think i´ve got the point now. Thanks everyone :-)! I´ve just tried some basic things and it seems to work. Now i just need to figure out what command my sensor needs to star sending data. Thanks again for the help.

Reply to
Max00007

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:

formatting link

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

Reply to
lpc.consultant

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.