Mercurial > ~darius > hgwebdir.cgi > stm32temp
annotate spi.c @ 30:435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Tue, 27 Nov 2012 13:19:11 +1030 |
parents | 58d76cf522ff |
children |
rev | line source |
---|---|
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 #include <stdint.h> |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 #include "spi.h" |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 #include "stm32f10x.h" |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 uint8_t |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 SPI_WriteByte(uint8_t out) { |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
7 uint8_t in = 0; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
8 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
9 /* Wait until the transmit buffer is empty */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 while (SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE) == RESET) |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
11 ; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
12 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
13 /* Send the byte */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 SPI_I2S_SendData(SPI1, out); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
15 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
16 /* Wait until a data is received */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
17 while (SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_RXNE) == RESET) |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
18 ; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
19 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 /* Get the received data */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 in = SPI_I2S_ReceiveData(SPI1); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 /* Return the shifted data */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 return (in); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
25 } |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
26 |