@@ -208,7 +208,7 void bsp_spi_init() | |||||
208 |
|
208 | |||
209 | void bsp_iic_init() |
|
209 | void bsp_iic_init() | |
210 | { |
|
210 | { | |
211 |
i2copenandconfig(i2c2,0, |
|
211 | i2copenandconfig(i2c2,0,10000,PF0,PF1); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void bsp_SD_init() |
|
214 | void bsp_SD_init() | |
@@ -306,3 +306,7 void bsp_GTerm_init() | |||||
306 |
|
306 | |||
307 |
|
307 | |||
308 |
|
308 | |||
|
309 | ||||
|
310 | ||||
|
311 | ||||
|
312 |
@@ -1,6 +1,9 | |||||
1 | CPU=stm32f4xxxG |
|
1 | CPU=stm32f4xxxG | |
2 | DEFINES+=BSP=\\\"BEAGLESYNTH\\\" |
|
2 | DEFINES+=BSP=\\\"BEAGLESYNTH\\\" | |
3 | beagleCp.target = beagleCp |
|
3 | beagleCp.target = beagleCp | |
4 |
beagleCp.commands = scp |
|
4 | beagleCp.commands = cd bin && scp $(QMAKE_TARGET).bin root@192.168.7.2://opt/stm32flashAje/hello.bin | |
5 | QMAKE_EXTRA_TARGETS += beagleCp |
|
5 | beagleCp131.target = beagleCp131 | |
|
6 | beagleCp131.commands = cd bin && scp $(QMAKE_TARGET).bin root@129.104.27.131://opt/stm32flashAje/hello.bin | |||
|
7 | QMAKE_EXTRA_TARGETS += beagleCp beagleCp131 | |||
|
8 | ||||
6 | UCMODEL=stm32f4 |
|
9 | UCMODEL=stm32f4 |
@@ -247,7 +247,7 void bsp_spi_init() | |||||
247 |
|
247 | |||
248 | void bsp_iic_init() |
|
248 | void bsp_iic_init() | |
249 | { |
|
249 | { | |
250 |
|
|
250 | i2copenandconfig(i2c1,0,100000,PB9,PB6); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | void bsp_SD_init() |
|
253 | void bsp_SD_init() |
@@ -3,12 +3,21 CONFIG += cpu | |||||
3 |
|
3 | |||
4 |
|
4 | |||
5 | UCMODEL=stm32f4 |
|
5 | UCMODEL=stm32f4 | |
6 |
DEFINES += CPUFREQ= |
|
6 | DEFINES += CPUFREQ=40000000 | |
7 |
|
7 | |||
8 |
|
|
8 | BSP = BEAGLESYNTH | |
9 | #BSP = SOLAR_LFR_PSU |
|
9 | #BSP = SOLAR_LFR_PSU | |
10 | BSP = STM32F4Eval |
|
10 | #BSP = STM32F4Eval | |
11 |
|
11 | |||
12 | SOURCES += \ |
|
12 | SOURCES += \ | |
13 | main.c |
|
13 | main.c | |
14 |
|
14 | |||
|
15 | ||||
|
16 | ||||
|
17 | ||||
|
18 | ||||
|
19 | #beagleCp.target = beagleCp | |||
|
20 | #beagleCp.commands = cd bin && scp $(QMAKE_TARGET).bin root@192.168.7.2://opt/stm32flashAje/hello.bin | |||
|
21 | #beagleCp131.target = beagleCp131 | |||
|
22 | #beagleCp131.commands = cd bin && scp $(QMAKE_TARGET).bin root@129.104.27.131://opt/stm32flashAje/hello.bin | |||
|
23 | #QMAKE_EXTRA_TARGETS += beagleCp beagleCp131 |
@@ -11,6 +11,7 | |||||
11 | #include <fonts.h> |
|
11 | #include <fonts.h> | |
12 | #include <stdlib.h> |
|
12 | #include <stdlib.h> | |
13 | #include <core.h> |
|
13 | #include <core.h> | |
|
14 | #include <malloc.h> | |||
14 |
|
15 | |||
15 |
|
16 | |||
16 | extern streamdevice* __opnfiles__[]; |
|
17 | extern streamdevice* __opnfiles__[]; | |
@@ -30,13 +31,21 extern streamdevice* __opnfiles__[]; | |||||
30 | #define PSU_DISABLE LED1 |
|
31 | #define PSU_DISABLE LED1 | |
31 | #endif |
|
32 | #endif | |
32 |
|
33 | |||
|
34 | void setUartAsStdout() | |||
|
35 | { | |||
|
36 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |||
|
37 | uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); | |||
|
38 | uartmkstreamdev(uart,fd1); | |||
|
39 | __opnfiles__[1] = fd1; | |||
|
40 | } | |||
33 |
|
41 | |||
34 | int main() |
|
42 | int main() | |
35 | { |
|
43 | { | |
36 | delay_100us(20000); |
|
44 | delay_100us(20000); | |
37 | INA226_t ina5VSens,ina33VSens,ina15VSens; |
|
45 | INA226_t ina5VSens,ina33VSens,ina15VSens; | |
38 | gpioset(PSU_DISABLE);//enable psu! |
|
46 | gpioset(PSU_DISABLE);//enable psu! | |
39 | ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_BLACK,1,LCD_COLOR_BLACK); |
|
47 | setUartAsStdout(); | |
|
48 | //ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_BLACK,1,LCD_COLOR_BLACK); | |||
40 | if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000)) |
|
49 | if(-1==ina226open(&ina33VSens,i2c2,INA226_MODE_SHUNT_VOLTAGE_CONTINUOUS|INA226_AVERAGES_16|INA226_BUS_CONV_8244us|INA226_SHUNT_CONV_8244us,0,0,15,1000000)) | |
41 | { |
|
50 | { | |
42 | printf("Can't open 3.3V monitor\n\r"); |
|
51 | printf("Can't open 3.3V monitor\n\r"); | |
@@ -55,9 +64,10 int main() | |||||
55 | current5V = ina226getCurrent(&ina5VSens); |
|
64 | current5V = ina226getCurrent(&ina5VSens); | |
56 | current33V = ina226getCurrent(&ina33VSens); |
|
65 | current33V = ina226getCurrent(&ina33VSens); | |
57 | current15V = ina226getCurrent(&ina15VSens); |
|
66 | current15V = ina226getCurrent(&ina15VSens); | |
58 | printf("%dmA\n",current15V/1000); |
|
67 | printf("%dmA\n\r",current15V/1000); | |
59 | printf("%dmA\n",current33V/1000); |
|
68 | printf("%dmA\n\r",current33V/1000); | |
60 | printf("%dmA\n",current5V/1000); |
|
69 | printf("%dmA\n\r",current5V/1000); | |
|
70 | delay_100us(10000); | |||
61 | } |
|
71 | } | |
62 | printf("Exit\n\r"); |
|
72 | printf("Exit\n\r"); | |
63 | return 0; |
|
73 | return 0; |
@@ -6,7 +6,7 UCMODEL=stm32f4 | |||||
6 |
|
6 | |||
7 | BSP = STM32F4Eval |
|
7 | BSP = STM32F4Eval | |
8 |
|
8 | |||
9 |
DEFINES += CPUFREQ= |
|
9 | DEFINES += CPUFREQ=40000000 | |
10 |
|
10 | |||
11 | SOURCES += \ |
|
11 | SOURCES += \ | |
12 | main.c |
|
12 | main.c |
@@ -26,9 +26,17 extern streamdevice* __opnfiles__[__MAX_ | |||||
26 | #define LCD_COLOR_CYAN 0x7FFF |
|
26 | #define LCD_COLOR_CYAN 0x7FFF | |
27 | #define LCD_COLOR_YELLOW 0xFFE0 |
|
27 | #define LCD_COLOR_YELLOW 0xFFE0 | |
28 |
|
28 | |||
|
29 | void testAudioDAC() | |||
|
30 | { | |||
|
31 | CS43L22_t dac; | |||
|
32 | cs43l22open(&dac,i2c1,0); | |||
|
33 | uint8_t ID= cs43l22getID(&dac); | |||
|
34 | printf("dac ID = %d\n\r",ID); | |||
|
35 | } | |||
29 |
|
36 | |||
30 | int main() |
|
37 | int main() | |
31 | { |
|
38 | { | |
|
39 | delay_100us(10000); | |||
32 | uint16_t innerbuffer[16]; |
|
40 | uint16_t innerbuffer[16]; | |
33 | uint16_t outterbuffer[16]; |
|
41 | uint16_t outterbuffer[16]; | |
34 | for(int i=0;i<16;i++)innerbuffer[i]=LCD_COLOR_BLUE; |
|
42 | for(int i=0;i<16;i++)innerbuffer[i]=LCD_COLOR_BLUE; | |
@@ -48,6 +56,8 int main() | |||||
48 | printf("Line cnt :\n \t%d\n",terminal0.lineCount); |
|
56 | printf("Line cnt :\n \t%d\n",terminal0.lineCount); | |
49 | printf("Column cnt :\n \t%d\n",terminal0.columnCount); |
|
57 | printf("Column cnt :\n \t%d\n",terminal0.columnCount); | |
50 | printf("CPU Freq :\n \t%dMHz\n",getCpuFreq()/1000000); |
|
58 | printf("CPU Freq :\n \t%dMHz\n",getCpuFreq()/1000000); | |
|
59 | //testAudioDAC(); | |||
|
60 | i2cwrite(i2c1,0x4a," ",1); | |||
51 | while(1) |
|
61 | while(1) | |
52 | { |
|
62 | { | |
53 | i%=1000; |
|
63 | i%=1000; |
@@ -29,7 +29,7 int ina226open(INA226_t *dev, i2c_t i2cd | |||||
29 | if(dev != NULL) |
|
29 | if(dev != NULL) | |
30 | { |
|
30 | { | |
31 | dev->i2cdev=i2cdev; |
|
31 | dev->i2cdev=i2cdev; | |
32 |
dev->devAddress = INA226_I2C_ADDRESS | (A0 & 1) | ((A1<< |
|
32 | dev->devAddress = INA226_I2C_ADDRESS | (A0 & 1) | ((A1<<2) & 5); | |
33 | printf("dev->devAddress = %x\n\r",dev->devAddress); |
|
33 | printf("dev->devAddress = %x\n\r",dev->devAddress); | |
34 | dev->shuntmOhm = shuntmOhm; |
|
34 | dev->shuntmOhm = shuntmOhm; | |
35 | dev->CurrentRangeuAmp = CurrentRangeuAmp; |
|
35 | dev->CurrentRangeuAmp = CurrentRangeuAmp; |
@@ -39,8 +39,7 i2c_t i2copen(int count) | |||||
39 | #define _INIT_DEV(_RCC_) \ |
|
39 | #define _INIT_DEV(_RCC_) \ | |
40 | RCC_APB1PeriphClockCmd(_RCC_, ENABLE); \ |
|
40 | RCC_APB1PeriphClockCmd(_RCC_, ENABLE); \ | |
41 | RCC_APB1PeriphResetCmd(_RCC_, ENABLE); \ |
|
41 | RCC_APB1PeriphResetCmd(_RCC_, ENABLE); \ | |
42 |
RCC_APB1PeriphResetCmd(_RCC_, DISABLE); |
|
42 | RCC_APB1PeriphResetCmd(_RCC_, DISABLE); | |
43 | RCC_APB1PeriphClockCmd(_RCC_, ENABLE); |
|
|||
44 |
|
43 | |||
45 | switch(count) |
|
44 | switch(count) | |
46 | { |
|
45 | { | |
@@ -70,7 +69,7 i2c_t i2copenandconfig(int count,uint32_ | |||||
70 | i2cclose(dev); |
|
69 | i2cclose(dev); | |
71 | i2csetpins(dev,SDA,SCL); |
|
70 | i2csetpins(dev,SDA,SCL); | |
72 | i2copen(count); |
|
71 | i2copen(count); | |
73 | i2cenable(count); |
|
72 | //i2cenable(count); | |
74 | //I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
73 | //I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
75 | i2csetspeed(dev,speed); |
|
74 | i2csetspeed(dev,speed); | |
76 | i2cenable(count); |
|
75 | i2cenable(count); | |
@@ -99,7 +98,7 int i2cclose(i2c_t dev) | |||||
99 |
|
98 | |||
100 | int i2csetpins(i2c_t dev, uint32_t SDA, uint32_t SCL) |
|
99 | int i2csetpins(i2c_t dev, uint32_t SDA, uint32_t SCL) | |
101 | { |
|
100 | { | |
102 |
if((dev< |
|
101 | if((dev<i2c4)&&(dev>=i2c1)) | |
103 | { |
|
102 | { | |
104 | gpio_t SDApin,SCLpin; |
|
103 | gpio_t SDApin,SCLpin; | |
105 | SDApin = gpioopen(SDA); |
|
104 | SDApin = gpioopen(SDA); | |
@@ -144,7 +143,7 int i2csetpins(i2c_t dev, uint32_t SDA, | |||||
144 |
|
143 | |||
145 | int i2cenable(i2c_t dev) |
|
144 | int i2cenable(i2c_t dev) | |
146 | { |
|
145 | { | |
147 |
if((dev< |
|
146 | if((dev<i2c4)&&(dev>=i2c1)) | |
148 | { |
|
147 | { | |
149 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
148 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
150 | _dev_->CR1 |=1 ; |
|
149 | _dev_->CR1 |=1 ; | |
@@ -155,7 +154,7 int i2cenable(i2c_t dev) | |||||
155 |
|
154 | |||
156 | int i2cdisable(i2c_t dev) |
|
155 | int i2cdisable(i2c_t dev) | |
157 | { |
|
156 | { | |
158 |
if((dev< |
|
157 | if((dev<i2c4)&&(dev>=i2c1)) | |
159 | { |
|
158 | { | |
160 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
159 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
161 | _dev_->CR1 &= ~1; |
|
160 | _dev_->CR1 &= ~1; | |
@@ -167,7 +166,7 int i2cdisable(i2c_t dev) | |||||
167 |
|
166 | |||
168 | int i2csetspeed(i2c_t dev,uint32_t speed) |
|
167 | int i2csetspeed(i2c_t dev,uint32_t speed) | |
169 | { |
|
168 | { | |
170 |
if((dev< |
|
169 | if((dev<i2c4)&&(dev>=i2c1)) | |
171 | { |
|
170 | { | |
172 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
171 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
173 | int32_t APB1Freq=getAPB1Freq()/1000000; |
|
172 | int32_t APB1Freq=getAPB1Freq()/1000000; | |
@@ -193,9 +192,9 int i2csetspeed(i2c_t dev,uint32_t speed | |||||
193 | } |
|
192 | } | |
194 | else |
|
193 | else | |
195 | { |
|
194 | { | |
196 |
|
|
195 | tmpreg &= ~(1<<15); | |
197 |
|
|
196 | tmpreg &= ~(0xfff); | |
198 |
|
|
197 | tmpreg |= 0xfff & (APB1Freq/(2*speed)); | |
199 | } |
|
198 | } | |
200 | _dev_->CCR=tmpreg; |
|
199 | _dev_->CCR=tmpreg; | |
201 | tmpreg=_dev_->TRISE; |
|
200 | tmpreg=_dev_->TRISE; | |
@@ -211,7 +210,7 int i2csetspeed(i2c_t dev,uint32_t speed | |||||
211 |
|
210 | |||
212 | int i2cbusy(i2c_t dev) |
|
211 | int i2cbusy(i2c_t dev) | |
213 | { |
|
212 | { | |
214 |
if((dev< |
|
213 | if((dev<i2c4)&&(dev>=i2c1)) | |
215 | { |
|
214 | { | |
216 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
215 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
217 | if((_dev_->SR2 & 2) ==2) return 1; /* Dev is busy */ |
|
216 | if((_dev_->SR2 & 2) ==2) return 1; /* Dev is busy */ | |
@@ -222,25 +221,37 int i2cbusy(i2c_t dev) | |||||
222 |
|
221 | |||
223 | int i2cwrite(i2c_t dev,char address,char* data,int count) |
|
222 | int i2cwrite(i2c_t dev,char address,char* data,int count) | |
224 | { |
|
223 | { | |
225 |
if((dev< |
|
224 | if((dev<i2c4)&&(dev>=i2c1)) | |
226 | { |
|
225 | { | |
227 | int timeout=i2ctimeout; |
|
226 | int timeout=i2ctimeout; | |
228 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
227 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
229 | while(i2cbusy(dev)) |
|
228 | while(i2cbusy(dev)) | |
230 | { |
|
229 | { | |
231 |
if(0==(timeout--)) |
|
230 | if(0==(timeout--)) | |
|
231 | { | |||
|
232 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
233 | return -1; | |||
|
234 | } | |||
232 | } |
|
235 | } | |
233 | _dev_->CR1 |= 1<<8; |
|
236 | _dev_->CR1 |= 1<<8; | |
234 | timeout=i2ctimeout; |
|
237 | timeout=i2ctimeout; | |
235 | while(!i2cStatusCheck(dev,((uint32_t)0x00030001))) |
|
238 | while(!i2cStatusCheck(dev,((uint32_t)0x00030001))) | |
236 | { |
|
239 | { | |
237 |
if(0==(timeout--)) |
|
240 | if(0==(timeout--)) | |
|
241 | { | |||
|
242 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
243 | return -1; | |||
|
244 | } | |||
238 | } |
|
245 | } | |
239 | _dev_->DR= address<<1; |
|
246 | _dev_->DR= address<<1; | |
240 | timeout=i2ctimeout; |
|
247 | timeout=i2ctimeout; | |
241 | while(!i2cStatusCheck(dev, ((uint32_t)0x00070082))) |
|
248 | while(!i2cStatusCheck(dev, ((uint32_t)0x00070082))) | |
242 | { |
|
249 | { | |
243 |
if(0==(timeout--)) |
|
250 | if(0==(timeout--)) | |
|
251 | { | |||
|
252 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
253 | return -1; | |||
|
254 | } | |||
244 | } |
|
255 | } | |
245 | address=_dev_->SR2; |
|
256 | address=_dev_->SR2; | |
246 | for(int i=0;i<count;i++) |
|
257 | for(int i=0;i<count;i++) | |
@@ -248,19 +259,31 int i2cwrite(i2c_t dev,char address,char | |||||
248 | timeout=i2ctimeout; |
|
259 | timeout=i2ctimeout; | |
249 | while(!i2cStatusCheck(dev,((uint32_t)0x00070080))) |
|
260 | while(!i2cStatusCheck(dev,((uint32_t)0x00070080))) | |
250 | { |
|
261 | { | |
251 |
if(0==(timeout--)) |
|
262 | if(0==(timeout--)) | |
|
263 | { | |||
|
264 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
265 | return -1; | |||
|
266 | } | |||
252 | } |
|
267 | } | |
253 | _dev_->DR= data[i]; |
|
268 | _dev_->DR= data[i]; | |
254 | } |
|
269 | } | |
255 | timeout=i2ctimeout; |
|
270 | timeout=i2ctimeout; | |
256 | while(!i2cStatusCheck(dev,1<<7)) |
|
271 | while(!i2cStatusCheck(dev,1<<7)) | |
257 | { |
|
272 | { | |
258 |
if(0==(timeout--)) |
|
273 | if(0==(timeout--)) | |
|
274 | { | |||
|
275 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
276 | return -1; | |||
|
277 | } | |||
259 | } |
|
278 | } | |
260 | timeout=i2ctimeout; |
|
279 | timeout=i2ctimeout; | |
261 | while(!i2cStatusCheck(dev,1<<2)) |
|
280 | while(!i2cStatusCheck(dev,1<<2)) | |
262 | { |
|
281 | { | |
263 |
if(0==(timeout--)) |
|
282 | if(0==(timeout--)) | |
|
283 | { | |||
|
284 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
285 | return -1; | |||
|
286 | } | |||
264 | } |
|
287 | } | |
265 | _dev_->CR1 |= 1<<9; |
|
288 | _dev_->CR1 |= 1<<9; | |
266 | return count; |
|
289 | return count; | |
@@ -270,25 +293,37 int i2cwrite(i2c_t dev,char address,char | |||||
270 |
|
293 | |||
271 | int i2cread(i2c_t dev,char address,char* data,int count) |
|
294 | int i2cread(i2c_t dev,char address,char* data,int count) | |
272 | { |
|
295 | { | |
273 |
if((dev< |
|
296 | if((dev<i2c4)&&(dev>=i2c1)) | |
274 | { |
|
297 | { | |
275 | int i=0; |
|
298 | int i=0; | |
276 | int timeout=i2ctimeout; |
|
299 | int timeout=i2ctimeout; | |
277 | while(i2cbusy(dev)) |
|
300 | while(i2cbusy(dev)) | |
278 | { |
|
301 | { | |
279 |
if(0==(timeout--)) |
|
302 | if(0==(timeout--)) | |
|
303 | { | |||
|
304 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
305 | return -1; | |||
|
306 | } | |||
280 | } |
|
307 | } | |
281 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
308 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
282 | _dev_->CR1 |= (1<<8) + (1<<10); |
|
309 | _dev_->CR1 |= (1<<8) + (1<<10); | |
283 | timeout=i2ctimeout; |
|
310 | timeout=i2ctimeout; | |
284 | while(!i2cStatusCheck(dev,0x00030001)) |
|
311 | while(!i2cStatusCheck(dev,0x00030001)) | |
285 | { |
|
312 | { | |
286 |
if(0==(timeout--)) |
|
313 | if(0==(timeout--)) | |
|
314 | { | |||
|
315 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
316 | return -1; | |||
|
317 | } | |||
287 | } |
|
318 | } | |
288 | _dev_->DR= (address<<1) + 1; |
|
319 | _dev_->DR= (address<<1) + 1; | |
289 | while(!i2cStatusCheck(dev,0x000002)) |
|
320 | while(!i2cStatusCheck(dev,0x000002)) | |
290 | { |
|
321 | { | |
291 |
if(0==(timeout--)) |
|
322 | if(0==(timeout--)) | |
|
323 | { | |||
|
324 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
325 | return -1; | |||
|
326 | } | |||
292 | } |
|
327 | } | |
293 | if(count==1) |
|
328 | if(count==1) | |
294 | { |
|
329 | { | |
@@ -300,7 +335,11 int i2cread(i2c_t dev,char address,char* | |||||
300 | timeout=i2ctimeout; |
|
335 | timeout=i2ctimeout; | |
301 | while(!i2cStatusCheck(dev,0x0000040)) |
|
336 | while(!i2cStatusCheck(dev,0x0000040)) | |
302 | { |
|
337 | { | |
303 |
if(0==(timeout--)) |
|
338 | if(0==(timeout--)) | |
|
339 | { | |||
|
340 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
341 | return -1; | |||
|
342 | } | |||
304 | } |
|
343 | } | |
305 | data[i]=_dev_->DR; |
|
344 | data[i]=_dev_->DR; | |
306 | } |
|
345 | } | |
@@ -309,13 +348,21 int i2cread(i2c_t dev,char address,char* | |||||
309 | timeout=i2ctimeout; |
|
348 | timeout=i2ctimeout; | |
310 | while(!i2cStatusCheck(dev,0x0000040)) |
|
349 | while(!i2cStatusCheck(dev,0x0000040)) | |
311 | { |
|
350 | { | |
312 |
if(0==(timeout--)) |
|
351 | if(0==(timeout--)) | |
|
352 | { | |||
|
353 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
354 | return -1; | |||
|
355 | } | |||
313 | } |
|
356 | } | |
314 | data[i]=_dev_->DR; |
|
357 | data[i]=_dev_->DR; | |
315 | timeout=i2ctimeout; |
|
358 | timeout=i2ctimeout; | |
316 | while(_dev_->CR1 & ((uint16_t)0x0200)) |
|
359 | while(_dev_->CR1 & ((uint16_t)0x0200)) | |
317 | { |
|
360 | { | |
318 |
if(0==(timeout--)) |
|
361 | if(0==(timeout--)) | |
|
362 | { | |||
|
363 | printf("Exited on timeout @ line %d\n\r",__LINE__); | |||
|
364 | return -1; | |||
|
365 | } | |||
319 | } |
|
366 | } | |
320 | _dev_->CR1 |= 1<<10; |
|
367 | _dev_->CR1 |= 1<<10; | |
321 | return count; |
|
368 | return count; | |
@@ -327,7 +374,7 int i2cread(i2c_t dev,char address,char* | |||||
327 | int i2cStatusCheck(i2c_t dev,int32_t flagMask) |
|
374 | int i2cStatusCheck(i2c_t dev,int32_t flagMask) | |
328 | { |
|
375 | { | |
329 | int32_t flag; |
|
376 | int32_t flag; | |
330 |
if((dev< |
|
377 | if((dev<i2c4)&&(dev>=i2c1)) | |
331 | { |
|
378 | { | |
332 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; |
|
379 | I2C_TypeDef* _dev_ = _i2c_dev_table[(int)dev]; | |
333 | flag= _dev_->SR1 + (_dev_->SR2<<16); |
|
380 | flag= _dev_->SR1 + (_dev_->SR2<<16); |
General Comments 0
You need to be logged in to leave comments.
Login now