summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author[email protected] <[email protected]>2011-11-02 08:17:40 +0000
committer[email protected] <[email protected]>2011-11-02 08:17:40 +0000
commit9de3512c8a463d188baaa48570a0cc4277251726 (patch)
treec81fc4cd7be29c5e8aa1cd94b116a5104ff84212
parent4f62f6e568ec4535d79400e65e16d17bc48c13e7 (diff)
fix ads7843 data fetching
The old code forgot to drop the MSB in the very first byte retrieved from ads7843 after a control byte. This will lead to data corruption especially in 16-Clocks per conversion mode. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1781 bbd45198-f89e-11dd-88c7-29a3b14d5316
-rw-r--r--bsp/stm32f10x/touch.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/bsp/stm32f10x/touch.c b/bsp/stm32f10x/touch.c
index f657562d0f..e41d840fde 100644
--- a/bsp/stm32f10x/touch.c
+++ b/bsp/stm32f10x/touch.c
@@ -92,14 +92,22 @@ static void rtgui_touch_calculate()
rt_uint16_t tmpy[10];
unsigned int i;
+ /* From the datasheet:
+ * When the very first CLK after the control byte comes in, the
+ * DOUT of ADS7843 is not valid. So we could only get 7bits from
+ * the first SPI_WriteByte. And the got the following 5 bits from
+ * another SPI_WriteByte.(aligned MSB)
+ */
for(i=0; i<10; i++)
{
CS_0();
- WriteDataTo7843(TOUCH_MSR_X); /* read X */
- tmpx[i] = SPI_WriteByte(0x00)<<4; /* read MSB bit[11:8] */
- tmpx[i] |= ((SPI_WriteByte(TOUCH_MSR_Y)>>4)&0x0F ); /* read LSB bit[7:0] */
- tmpy[i] = SPI_WriteByte(0x00)<<4; /* read MSB bit[11:8] */
- tmpy[i] |= ((SPI_WriteByte(0x00)>>4)&0x0F ); /* read LSB bit[7:0] */
+ WriteDataTo7843(TOUCH_MSR_X);
+ tmpx[i] = (SPI_WriteByte(0x00) & 0x7F) << 5;
+ tmpx[i] |= (SPI_WriteByte(TOUCH_MSR_Y) >> 3) & 0x1F;
+
+ tmpy[i] = (SPI_WriteByte(0x00) & 0x7F) << 5;
+ tmpy[i] |= (SPI_WriteByte(0x00) >> 3) & 0x1F;
+
WriteDataTo7843( 1<<7 ); /* ���ж� */
CS_1();
}