Rev Author Line No. Line
2764 kaklik 1 #include <main.h>
2763 kaklik 2  
2765 kaklik 3 /*
4 MPL115A1 SDN - +5V (always power on)
5 MPL115A1 CSN - PIN_C2
6 MPL115A1 SDO - PIN_C4 (twisted?)
7 MPL115A1 SDI - PIN_C5 (twisted?)
8 MPL115A1 SCK - PIN_C3
9 MPL115A1 GND - GND
10 MPL115A1 VDD - +5V
11 */
12  
2763 kaklik 13 #define CSN_SPI PIN_C2
14 int8 address, uiTadc, data ;
15  
16  
17 // SPI mode definitions.
18 #define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
19 #define SPI_MODE_1 (SPI_L_TO_H)
20 #define SPI_MODE_2 (SPI_H_TO_L)
21 #define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
22  
23  
24 void main()
25 {
26 printf("Start\n\r");
27  
28 setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);
29  
30 output_high(CSN_SPI);
31  
32 delay_ms(100);
33  
34 while(true)
35 {
36 data = 5; //just to be sure that the value is updated
37  
38 //Start temperature and pressure conversion
39 address = 0x24;
40 address &= 0x7F;
41  
42 output_low(CSN_SPI);
43 delay_ms(1);
44 spi_write(address);
45 delay_ms(1);
46 spi_write(0x00);
47 delay_ms(1);
48 output_high(CSN_SPI);
49 delay_ms(2);
50  
51  
52 // get MSB for Pressure
53 address = 0x00;
54 address |= 0x80;
55  
56 output_low(CSN_SPI);
57 delay_ms(1);
58 spi_write(address);
59 delay_ms(1);
60 data = spi_read(0x00);
61 delay_ms(1);
62 output_high(CSN_SPI);
63  
64 printf("%u\n\r", data);
65  
66 //uiTadc = (unsigned int) data << 8;
67 //printf("%u\n\r", uiTadc);
68  
69  
70 delay_ms(100);
71 }
72  
73 }