Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:be1765e9885e, committed 2011-01-25
- Comitter:
- michelebavaro
- Date:
- Tue Jan 25 11:26:16 2011 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r be1765e9885e main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jan 25 11:26:16 2011 +0000 @@ -0,0 +1,95 @@ +#include "mbed.h" +#include "max2769tw.h" +#include "max2769ssp0.h" + +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +#define N_BYTES (16*1024) +#define N_XFER (N_BYTES / sizeof(uint16_t)) + +Serial pc(USBTX, USBRX); + +MAX2769TW spiGpsCtl(p24, p25, p26); // data, clock, chip select + +MAX2769SSP0 spiGpsAdc(p11, p13, p14); // data, clock, frame + +const unsigned int gpsConfRegArray[10] = + {0x82938E30, + 0x85500081, + 0xEAFE8062, + 0x9AC00003, + 0x00780084, + 0x87D3E705, + 0x00010006, + 0x10061B17, + 0x1E0F4018, + 0x14C04029}; + + +int main() { + int k; + uint16_t *ptMem16; + + pc.baud(115200); + + myled1 = myled2 = myled3 = myled4 = 1; + wait(1); + myled1 = myled2 = myled3 = myled4 = 1; + + // + // PROGRAM THE MAX2769 + // + myled2 = 1; + for (k=0; k<10; k++) { + myled1 = 1; + spiGpsCtl.SendReg(gpsConfRegArray[k]); + myled1 = 0; + } + myled2 = 0; + + // + // GET THE DATA SNAPSHOT FROM THE GPS FRONT-END + // + ptMem16 = (uint16_t*) malloc(N_BYTES); + if (NULL != ptMem16) { + // Write in memory, probably need DMA later + myled3 = 1; + memset(ptMem16, 0, N_BYTES); + spiGpsAdc.Read(ptMem16, N_XFER); + myled3 = 0; + } + + // + // SEND SOME DEBUG DATA TO THE SERIAL PORT + // + if (NULL != ptMem16) { + k = 0; + while (k < N_XFER) { + myled2 = 1; + pc.printf("%04x:%04x%04x%04x%04x%04x%04x%04x%04x\n", + k*sizeof(uint16_t), + ptMem16[k+ 0], ptMem16[k+ 1], ptMem16[k+ 2], ptMem16[k+ 3], + ptMem16[k+ 4], ptMem16[k+ 5], ptMem16[k+ 6], ptMem16[k+ 7] ); + k += 8; + myled2 = 0; + } + } + + // Free the allocated memory + if (NULL != ptMem16) { + free(ptMem16); + ptMem16 = NULL; + } + + // Go idle + while (1) { + myled4 = 1; + wait(1); + myled4 = 0; + wait(1); + } +} +
diff -r 000000000000 -r be1765e9885e max2769ssp0.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max2769ssp0.cpp Tue Jan 25 11:26:16 2011 +0000 @@ -0,0 +1,135 @@ +#include "mbed.h" +#include "max2769ssp0.h" + + +extern "C" void MYSSP0_IRQHandler(void) __irq; + +// CONSTRUCTOR +MAX2769SSP0::MAX2769SSP0(PinName _mosi=p11, PinName _sck=p13, PinName _ssel=p14) { + /* + * DEFAULT PORT IS SSP0, others are not supported + */ + if ( (_mosi == p11) && (_sck == p13) && (_ssel == p14) ) { + sppx = 0; + // Turn on SSP0 periferal + LPC_SC->PCONP |= (0x01UL << 21); + // Turn on the SSP0 clock + LPC_SC->PCLKSEL1 |= (0x01U << 10); // Turn on peripheral clock + // DIP11 is P0.18 + LPC_PINCON->PINSEL1 &= ~(3UL << 4); // Reset P0.18 + LPC_PINCON->PINSEL1 |= (2UL << 4); // Set P0.18 to MOSI0 + LPC_PINCON->PINMODE1 &= ~(3UL << 4); // + LPC_PINCON->PINMODE1 |= (2UL << 4); // Set P0.18 with no pull-up or pull-down + // DIP12 is P0.17 + LPC_PINCON->PINSEL1 &= ~(3UL << 2); // Reset P0.17 + LPC_PINCON->PINSEL1 |= (2UL << 2); // Set P0.17 to MISO0 + LPC_PINCON->PINMODE1 &= ~(3UL << 2); // + LPC_PINCON->PINMODE1 |= (2UL << 2); // Set P0.17 with no pull-up or pull-down + // DIP13 is P0.15 + LPC_PINCON->PINSEL0 &= ~(3UL << 30); // Reset P0.15 + LPC_PINCON->PINSEL0 |= (2UL << 30); // Set P0.15 to SCK0 + LPC_PINCON->PINMODE0 &= ~(3UL << 30); // + LPC_PINCON->PINMODE0 |= (2UL << 30); // Set P0.15 with no pull-up or pull-down + // DIP14 is P0.16 + LPC_PINCON->PINSEL1 &= ~(3UL << 0); // Reset P0.16 + LPC_PINCON->PINSEL1 |= (2UL << 0); // Set P0.16 to SSEL0 + LPC_PINCON->PINMODE1 &= ~(3UL << 0); // + LPC_PINCON->PINMODE1 |= (2UL << 0); // Set P0.16 with no pull-up or pull-down + + // Configure interrupts for SSP0 + LPC_SSP0->IMSC = + (1UL << 0) | // Receive overrun + (1UL << 1) | // Receive timeout + (0UL << 2) | // RX FIFO half full + (0UL << 3); // TX FIFO half empty + NVIC_SetVector(SSP0_IRQn, (uint32_t) MYSSP0_IRQHandler); + NVIC_EnableIRQ(SSP0_IRQn); + + // Configure SSP0 + LPC_SSP0->CR0 = + ( 0xFUL << 0) | // 16 bits transfers + ( 1UL << 4) | // Texas mode + (0x00UL << 8); // Serial clock rate + // Not really relevant since we are in slave mode + LPC_SSP0->CPSR = 0; + + LPC_SSP0->CR1 = + ( 0UL << 0) | // Loopback mode disabled + ( 0UL << 1) | // SSP controller disabled + ( 1UL << 2) | // Slave mode! + ( 1UL << 3); // Slave output is disabled + + LPC_SSP0->DMACR = + ( 0UL << 0) | // DMA disabled on RX path + ( 0UL << 1); // DMA disabled on TX path + + } else { + sppx = -1; + } +} + + +// DISTRUCTOR +MAX2769SSP0::~MAX2769SSP0() { + // do nothing +} + +// +void MAX2769SSP0::Read(uint16_t *_puiBuff, uint32_t _iLocations) { + int k; + + // Sanity check, port is not valid + if (sppx < 0) { + error("%s; this SSP port is not valid\n", __FUNCTION__); + } + + // Sanity check, buffer pointer is not valid + if (_puiBuff == NULL) { + error("%s; buffer pointer %p is not valid\n", __FUNCTION__, _puiBuff); + } + + //LPC_SSP0->DR = 0x5555; + if (LPC_SSP0->SR & 0x01) { + fprintf(stderr, "SSP0: TX FIFO empty\n"); + } else { + if (LPC_SSP0->SR & 0x02) { + fprintf(stderr, "SSP0: TX FIFO not full\n"); + } else { + fprintf(stderr, "SSP0: TX FIFO full\n"); + } + } + if (LPC_SSP0->SR & 0x04) { + if (LPC_SSP0->SR & 0x08) { + fprintf(stderr, "SSP0: RX FIFO full\n"); + } else { + fprintf(stderr, "SSP0: RX FIFO not full\n"); + } + } else { + fprintf(stderr, "SSP0: RX FIFO empty\n"); + } + if (LPC_SSP0->SR & 0x10) { + fprintf(stderr, "SSP0: BUSY\n"); + } else { + fprintf(stderr, "SSP0: IDLE\n"); + } + + k=0; + while (k < _iLocations) { + if (LPC_SSP0->SR & 0x4) { // if the RX FIFO is not empty + _puiBuff[k++] = (uint16_t) (LPC_SSP0->DR & 0xFFFF); + } + } +} + + +// MYSSP0_IRQHandler +extern "C" void MYSSP0_IRQHandler(void) __irq { + if (LPC_SSP0->MIS & 0x1UL) { + myled1 = 1; + LPC_SSP0->ICR &= ~0x1UL; + } + if (LPC_SSP0->MIS & 0x2UL) { + myled2 = 1; + LPC_SSP0->ICR &= ~0x2UL; + } +}
diff -r 000000000000 -r be1765e9885e max2769ssp0.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max2769ssp0.h Tue Jan 25 11:26:16 2011 +0000 @@ -0,0 +1,58 @@ +#ifndef MAX2769SSP0_H +#define MAX2769SSP0_H + +#include "mbed.h" + +extern Serial pc; +extern DigitalOut myled1; +extern DigitalOut myled2; + +/** An MAX2769SSP0 class + * It configures a SSP0 slave with TI protocol + * @author Michele Bavaro + * More details about the function goes here + * + * An example: + * @code + * #include "max2769ssp0.h" + * #include "mbed.h" + * + * MAX2769SSP0 adcSSP0(p11, p12, p13, p14); + * const uint16_t *puiMem; + * + * void main() + * { + * + * } + * @endcode + */ +class MAX2769SSP0 +{ + private: + int sppx; + + public: + /** Creates an MAX2769SSP0 object to program the chip + * + * @param _mosi Data Digital Input of 3-Wire Serial Interface. + * @param _sck Clock Digital Input of 3-Wire Serial Interface. + * Active when CS is low. Data is clocked in on the rising + * edge of the SCLK. + * @param _ssel Chip-Select Logic Input of 3-Wire Serial Interface + * Set CS low to allow serial data to shift in. Set CS high + * when the loading action is completed. + */ + MAX2769SSP0(PinName _mosi, PinName _sck, PinName _ssel); + + /** Destructs the MAX2769SSP0 object */ + ~MAX2769SSP0(); + + /** Reads from SSP0 into memory + * + * @param _puiMem Pointer to a 16-bits aligned memory space where data will be written + * @param _iSize Number of locations of the memory to be written + */ + void Read(uint16_t *_puiMem, uint32_t _iLocations); + +}; +#endif /* MAX2769SSP0_H */ \ No newline at end of file
diff -r 000000000000 -r be1765e9885e max2769tw.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max2769tw.cpp Tue Jan 25 11:26:16 2011 +0000 @@ -0,0 +1,35 @@ +#include "mbed.h" +#include "max2769tw.h" + +MAX2769TW::MAX2769TW(PinName _sData, PinName _sClk, PinName _sCs) : + sData(_sData), sClk(_sClk), sCs(_sCs) +{ + sData = 0; + sClk = 0; + sCs = 1; +} + +MAX2769TW::~MAX2769TW() { + // do nothing +} + +void MAX2769TW::SendReg(uint32_t _uiReg) { + int k; + + wait_us(3); sClk = 1; + wait_us(3); sClk = 0; + wait_us(3); sCs = 0; + for (k=31; k>=0; k--) { + if ((_uiReg >> k) & 0x1) { + sData = 1; + } else { + sData = 0; + } + wait_us(3); sClk = 1; + wait_us(3); sClk = 0; + } + wait_us(3); sCs = 1; + wait_us(3); sClk = 1; + wait_us(3); sClk = 0; + sData = 0; +} \ No newline at end of file
diff -r 000000000000 -r be1765e9885e max2769tw.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/max2769tw.h Tue Jan 25 11:26:16 2011 +0000 @@ -0,0 +1,59 @@ +#ifndef MAX2769TW_H +#define MAX2769TW_H + +#include "mbed.h" + +/** An MAX2769TW class + * It uses the Three Wire peripheral of the LPC1768 + * @author mbavaro + * More details about the function goes here + * + * An example: + * @code + * #include "MAX2769TW.h" + * #include "mbed.h" + * + * MAX2769TW gpsSpi(p24, p25, p26); + * const uint32_t confArray[10] = {...}; + * + * void main() + * { + * int k; + * + * for (k=0; k<10; k++) { + * gpsSpi.SendReg(confArray[k]); + * } + * + * } + * @endcode + */ +class MAX2769TW +{ + private: + DigitalOut sData; + DigitalOut sClk; + DigitalOut sCs; + + public: + /** Creates an MAX2769TW object to program the chip + * + * @param _sData Data Digital Input of 3-Wire Serial Interface + * @param _sClk Clock Digital Input of 3-Wire Serial Interface. + * Active when CS is low. Data is clocked in on the rising + * edge of the SCLK. + * @param _sCs Chip-Select Logic Input of 3-Wire Serial Interface. + * Set CS low to allow serial data to shift in. Set CS high + * when the loading action is completed. + */ + MAX2769TW(PinName _sData, PinName _sClk, PinName _sCs); + + /** Destructs the MAX2769TW object */ + ~MAX2769TW(); + + /** Streams the register content compliant with the 3-Wire protocol + * + * @param uiReg The 32-bit configuration register + */ + void SendReg(uint32_t _uiReg); +}; +#endif /* MAX2769TW_H */ \ No newline at end of file
diff -r 000000000000 -r be1765e9885e mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jan 25 11:26:16 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e