SPI

Dependencies:   mcp3008 mbed

Committer:
javiervicente
Date:
Tue Dec 01 11:55:38 2020 +0000
Revision:
5:fa5a1d23025d
Parent:
4:0bd89699719e
Ejemplo SPI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ryood 0:0e326a52b0f4 1 #include "mbed.h"
ryood 0:0e326a52b0f4 2 #include "mcp3008.h"
ryood 0:0e326a52b0f4 3
ryood 3:88504897a2e8 4 #define SPI_CLOCK (1312500)
ryood 2:492523fce75e 5
javiervicente 5:fa5a1d23025d 6 Serial pc(USBTX, USBRX); // tx, rx
javiervicente 5:fa5a1d23025d 7
ryood 3:88504897a2e8 8 //SPI (PinName mosi, PinName miso, PinName sclk, PinName ssel=NC)
ryood 3:88504897a2e8 9 SPI spiM(D4, D5, D3);
ryood 3:88504897a2e8 10 MCP3008 mcp3008_0(&spiM, D6);
javiervicente 5:fa5a1d23025d 11
ryood 2:492523fce75e 12
ryood 0:0e326a52b0f4 13 int main()
ryood 0:0e326a52b0f4 14 {
javiervicente 5:fa5a1d23025d 15 pc.baud(115200);
ryood 2:492523fce75e 16 spiM.frequency(SPI_CLOCK);
ryood 0:0e326a52b0f4 17
ryood 2:492523fce75e 18 uint16_t v0[8];
ryood 0:0e326a52b0f4 19
ryood 0:0e326a52b0f4 20 for (;;) {
ryood 0:0e326a52b0f4 21 for (int i = 0; i < 8; i++) {
ryood 2:492523fce75e 22 v0[i] = mcp3008_0.read_input_u16(i);
ryood 0:0e326a52b0f4 23 }
ryood 0:0e326a52b0f4 24
ryood 0:0e326a52b0f4 25 for (int i = 0; i < 8; i++) {
javiervicente 5:fa5a1d23025d 26 pc.printf("%4d\t", v0[i]);
javiervicente 5:fa5a1d23025d 27 }
javiervicente 5:fa5a1d23025d 28 pc.printf("\r\n");
ryood 0:0e326a52b0f4 29
ryood 0:0e326a52b0f4 30 wait(0.2);
ryood 0:0e326a52b0f4 31 }
ryood 0:0e326a52b0f4 32 }
ryood 0:0e326a52b0f4 33