| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907 |
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 1
- C251 COMPILER V5.60.0, COMPILATION OF MODULE AS7341
- OBJECT MODULE PLACED IN AS7341.OBJ
- COMPILER INVOKED BY: C:\Keil_v5\C251\BIN\C251.EXE AS7341.c XSMALL INTR2 BROWSE DEBUG
- stmt level source
- 1 #include "AS7341.h"
- 2 #include "STC32G.h"
- 3 #include <intrins.h>
- 4 #include "delay.h"
- 5
- 6 sbit sda=P0^6; //数据线
- 7 sbit scl=P0^5; //时钟线
- 8
- 9 eMode_t measureMode;
- 10 void AS7341_IIC_Init(void){
- 11 1
- 12 1 sda=1;
- 13 1 scl=1;
- 14 1 delay2us();
- 15 1 delay2us();
- 16 1 }
- 17
- 18
- 19 void AS7341_IIC_Start(void){
- 20 1 sda=1;
- 21 1 delay2us();
- 22 1 scl=1;
- 23 1 delay2us();
- 24 1 sda=0;
- 25 1 delay2us();
- 26 1 scl=0;
- 27 1 delay2us();
- 28 1 }
- 29
- 30 void AS7341_IIC_Stop(void){
- 31 1 sda=0;
- 32 1 delay2us();
- 33 1 scl=1;
- 34 1 delay2us();
- 35 1 sda=1;
- 36 1 delay2us();
- 37 1 scl=0;
- 38 1 delay2us();
- 39 1 }
- 40
- 41 unsigned char AS7341_IIC_Wait_Ack(void){
- 42 1 bit ack1=0;
- 43 1
- 44 1 sda=1;
- 45 1 delay2us();
- 46 1
- 47 1 scl=1;
- 48 1 delay2us();
- 49 1
- 50 1 ack1=sda;
- 51 1
- 52 1 scl=0;
- 53 1 delay2us();
- 54 1
- 55 1 return ack1;
- 56 1 }
- 57
- 58 void AS7341_IIC_Ack(void){
- 59 1 sda=0;
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 2
- 60 1 delay2us();
- 61 1
- 62 1 scl=1;
- 63 1 delay2us();
- 64 1 scl=0;
- 65 1 delay2us();
- 66 1 }
- 67
- 68 void AS7341_IIC_NAck(void){
- 69 1 scl=1;
- 70 1 delay2us();
- 71 1 sda=0;
- 72 1 scl=0;
- 73 1 delay2us();
- 74 1 }
- 75
- 76 void AS7341_IIC_Send_Byte(unsigned char DATA){
- 77 1
- 78 1 unsigned char Bit_Counter=8;
- 79 1 while(Bit_Counter>0)
- 80 1 {
- 81 2
- 82 2 sda=(bit)(DATA&0x80);
- 83 2 DATA<<=1;
- 84 2
- 85 2 scl=1;
- 86 2 delay2us();
- 87 2 scl=0;
- 88 2 delay2us();
- 89 2
- 90 2 Bit_Counter--;
- 91 2 }
- 92 1 }
- 93
- 94 unsigned char AS7341_IIC_Read_Byte(unsigned char ack){
- 95 1 unsigned char x=0,y=8;
- 96 1
- 97 1 sda=1;
- 98 1
- 99 1 while(y>0)
- 100 1 {
- 101 2 scl=1;
- 102 2 delay2us();
- 103 2
- 104 2
- 105 2 if(sda)
- 106 2 x=x|0x01;
- 107 2 else
- 108 2 x=x&0xfe;
- 109 2
- 110 2
- 111 2 scl=0;
- 112 2 delay2us();
- 113 2
- 114 2 if(y>1)
- 115 2 x=x<<1;
- 116 2
- 117 2 y--;
- 118 2 }
- 119 1 if(!ack)
- 120 1 AS7341_IIC_NAck();
- 121 1 else
- 122 1 AS7341_IIC_Ack();
- 123 1 return x;
- 124 1 }
- 125
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 3
- 126 /******************************************************************************
- 127 function: Read one byte of data to AS7341 via I2C
- 128 parameter:
- 129 Addr: Register address
- 130 Info:
- 131 ******************************************************************************/
- 132 UBYTE AS7341_Read_Byte(UBYTE Addr)
- 133 {
- 134 1 UBYTE reg_data=0;
- 135 1
- 136 1 AS7341_IIC_Start();
- 137 1 AS7341_IIC_Send_Byte(AS7341_ADDRESS << 1 | Write_BIT);
- 138 1 if(AS7341_IIC_Wait_Ack())return 0;
- 139 1 AS7341_IIC_Send_Byte(Addr);
- 140 1 if(AS7341_IIC_Wait_Ack())return 0;
- 141 1
- 142 1 AS7341_IIC_Start();
- 143 1 AS7341_IIC_Send_Byte(AS7341_ADDRESS << 1 | Read_BIT);
- 144 1 if(AS7341_IIC_Wait_Ack())return 0;
- 145 1 reg_data= AS7341_IIC_Read_Byte(1);
- 146 1
- 147 1 AS7341_IIC_Stop();
- 148 1
- 149 1 return reg_data;
- 150 1 }
- 151
- 152 ///******************************************************************************
- 153 //function: Send one byte of data to AS7341 via I2C
- 154 //parameter:
- 155 // Addr: Register address
- 156 // Value: Write to the value of the register
- 157 //Info:
- 158 //******************************************************************************/
- 159 ///**
- 160 // * @brief AS7341写数据
- 161 // */
- 162 UBYTE AS7341_Write_Byte(UBYTE Addr, UBYTE Value)
- 163 {
- 164 1
- 165 1
- 166 1 AS7341_IIC_Start();
- 167 1
- 168 1 AS7341_IIC_Send_Byte(AS7341_ADDRESS << 1 | Write_BIT);
- 169 1 if(AS7341_IIC_Wait_Ack())return 0;
- 170 1 AS7341_IIC_Send_Byte(Addr);
- 171 1 if(AS7341_IIC_Wait_Ack())return 0;
- 172 1 AS7341_IIC_Send_Byte(Value);
- 173 1 if(AS7341_IIC_Wait_Ack())return 0;
- 174 1
- 175 1 AS7341_IIC_Stop();
- 176 1 delay2ms();
- 177 1 return 1;
- 178 1 }
- 179
- 180 ///******************************************************************************
- 181 //function: AS7341 Initialization
- 182 //parameter:
- 183 //Info:
- 184 //******************************************************************************/
- 185 UBYTE AS7341_Init(eMode_t mode)
- 186 {
- 187 1 // DEV_I2C_Init(AS7341_ADDRESS<<1);//8-bit address
- 188 1 // printf("ID = 0x%x\r\n",AS7341_Read_Byte(AS7341_ID));//get AS7341 id
- 189 1 AS7341_Enable(true);
- 190 1 /////////////////////////////measureMode = mode;
- 191 1 return 0;
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 4
- 192 1 }
- *** WARNING C47 IN LINE 185 OF AS7341.c: 'mode': unreferenced parameter
- 193
- 194 ///******************************************************************************
- 195 //function: enable PON
- 196 //info: power on
- 197 //******************************************************************************/
- 198 void AS7341_Enable(int flag)
- 199 {
- 200 1 UBYTE data0, data1,aa;
- 201 1 data0 = AS7341_Read_Byte(AS7341_ENABLE);
- 202 1 if (flag == true)
- 203 1 {
- 204 2 data0 = data0 | (1 << 0);
- 205 2 }
- 206 1 else
- 207 1 {
- 208 2 data0 = data0 & (~1);
- 209 2 }
- 210 1 aa=AS7341_Write_Byte(AS7341_ENABLE, data0);
- 211 1 // DEV_Delay_ms(500);
- 212 1 ////////////////////////////////vTaskDelay(500 / portTICK_PERIOD_MS);
- 213 1 data1 = AS7341_Read_Byte(AS7341_ENABLE);
- 214 1 if (data1 == data0){
- 215 2 //printf("Initialization is complete !\r\n");
- 216 2 }else{
- 217 2 //printf("initialization is failure !\r\n");
- 218 2 //printf("Please check whether the IIC pin is connected correctly and whether the IIC function is
- - normal \r\n");
- 219 2 //printf("Please press the reset button or run the program again after checking \r\n");
- 220 2 while (1)
- 221 2 ;
- 222 2 }
- 223 1 aa=AS7341_Write_Byte(0x00, 0x30);
- 224 1 }
- 225
- 226 ///******************************************************************************
- 227 //function: enable Spectral measure
- 228 //info:
- 229 //******************************************************************************/
- 230 void AS7341_EnableSpectralMeasure(int flag) // Enable spectral measurement
- 231 {
- 232 1 UBYTE data0,aa;
- 233 1 data0 = AS7341_Read_Byte(AS7341_ENABLE);
- 234 1 if (flag == true)
- 235 1 {
- 236 2 data0 = data0 | (1 << 1);
- 237 2 }
- 238 1 else
- 239 1 {
- 240 2 data0 = data0 & (~(1 << 1));
- 241 2 }
- 242 1 aa=AS7341_Write_Byte(AS7341_ENABLE, data0);
- 243 1 }
- 244
- 245 ///******************************************************************************
- 246 //function: enable SMUX
- 247 //info:
- 248 //******************************************************************************/
- 249 void AS7341_EnableSMUX(int flag) // Enable multiplexer
- 250 /*The other available channels can be accessed by amultiplexer (SMUX) connecting them to one of the inter
- -nal ADCs.*/
- 251 {
- 252 1 UBYTE data0,aa;
- 253 1 data0 = AS7341_Read_Byte(AS7341_ENABLE);
- 254 1 if (flag == true)
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 5
- 255 1 {
- 256 2 data0 = data0 | (1 << 4);
- 257 2 }
- 258 1 else
- 259 1 {
- 260 2 data0 = data0 & (~(1 << 4));
- 261 2 }
- 262 1 aa=AS7341_Write_Byte(AS7341_ENABLE, data0);
- 263 1 }
- 264
- 265 ///******************************************************************************
- 266 //function: enable flicker detection
- 267 //info:
- 268 //******************************************************************************/
- 269 void AS7341_EnableFlickerDetection(int flag)
- 270 {
- 271 1
- 272 1 UBYTE data0,aa;
- 273 1 data0 = AS7341_Read_Byte(AS7341_ENABLE);
- 274 1 if (flag == true)
- 275 1 {
- 276 2 data0 = data0 | (1 << 6);
- 277 2 }
- 278 1 else
- 279 1 {
- 280 2 data0 = data0 & (~(1 << 6));
- 281 2 }
- 282 1 aa=AS7341_Write_Byte(AS7341_ENABLE, data0);
- 283 1 }
- 284
- 285 ///******************************************************************************
- 286 //function: choose model for spectral measurement
- 287 //info:
- 288 //******************************************************************************/
- 289 void AS7341_Config(eMode_t mode)
- 290 {
- 291 1 UBYTE data0,aa;
- 292 1 AS7341_SetBank(1);
- 293 1 data0 = AS7341_Read_Byte(AS7341_CONFIG);
- 294 1 switch (mode)
- 295 1 {
- 296 2 case eSpm:
- 297 2 {
- 298 3 data0 = (data0 & (~3)) | eSpm;
- 299 3 };
- 300 2 break;
- 301 2 case eSyns:
- 302 2 {
- 303 3 data0 = (data0 & (~3)) | eSyns;
- 304 3 };
- 305 2 break;
- 306 2 case eSynd:
- 307 2 {
- 308 3 data0 = (data0 & (~3)) | eSynd;
- 309 3 };
- 310 2 break;
- 311 2 default:
- 312 2 break;
- 313 2 }
- 314 1 aa=AS7341_Write_Byte(AS7341_CONFIG, data0);
- 315 1 AS7341_SetBank(0);
- 316 1 }
- 317
- 318 ///******************************************************************************
- 319 //function: Configure SMUX for sensors F1-4, Clear and NIR
- 320 //info:
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 6
- 321 //******************************************************************************/
- 322 void F1F4_Clear_NIR()
- 323 {
- 324 1 UBYTE aa;
- 325 1 aa=AS7341_Write_Byte(0x00, 0x30);
- 326 1 aa=AS7341_Write_Byte(0x01, 0x01);
- 327 1 aa=AS7341_Write_Byte(0x02, 0x00);
- 328 1 aa=AS7341_Write_Byte(0x03, 0x00);
- 329 1 aa=AS7341_Write_Byte(0x04, 0x00);
- 330 1 aa=AS7341_Write_Byte(0x05, 0x42);
- 331 1 aa=AS7341_Write_Byte(0x06, 0x00);
- 332 1 aa=AS7341_Write_Byte(0x07, 0x00);
- 333 1 aa=AS7341_Write_Byte(0x08, 0x50);
- 334 1 aa=AS7341_Write_Byte(0x09, 0x00);
- 335 1 aa=AS7341_Write_Byte(0x0A, 0x00);
- 336 1 aa=AS7341_Write_Byte(0x0B, 0x00);
- 337 1 aa=AS7341_Write_Byte(0x0C, 0x20);
- 338 1 aa=AS7341_Write_Byte(0x0D, 0x04);
- 339 1 aa=AS7341_Write_Byte(0x0E, 0x00);
- 340 1 aa=AS7341_Write_Byte(0x0F, 0x30);
- 341 1 aa=AS7341_Write_Byte(0x10, 0x01);
- 342 1 aa=AS7341_Write_Byte(0x11, 0x50);
- 343 1 aa=AS7341_Write_Byte(0x12, 0x00);
- 344 1 aa=AS7341_Write_Byte(0x13, 0x06);
- 345 1 }
- 346 ///******************************************************************************
- 347 //function: Configure SMUX for sensors F5-8, Clear and NIR
- 348 //info:
- 349 //******************************************************************************/
- 350 void F5F8_Clear_NIR()
- 351 {
- 352 1 UBYTE aa;
- 353 1 aa=AS7341_Write_Byte(0x00, 0x00);
- 354 1 aa=AS7341_Write_Byte(0x01, 0x00);
- 355 1 aa=AS7341_Write_Byte(0x02, 0x00);
- 356 1 aa=AS7341_Write_Byte(0x03, 0x40);
- 357 1 aa=AS7341_Write_Byte(0x04, 0x02);
- 358 1 aa=AS7341_Write_Byte(0x05, 0x00);
- 359 1 aa=AS7341_Write_Byte(0x06, 0x10);
- 360 1 aa=AS7341_Write_Byte(0x07, 0x03);
- 361 1 aa=AS7341_Write_Byte(0x08, 0x50);
- 362 1 aa=AS7341_Write_Byte(0x09, 0x10);
- 363 1 aa=AS7341_Write_Byte(0x0A, 0x03);
- 364 1 aa=AS7341_Write_Byte(0x0B, 0x00);
- 365 1 aa=AS7341_Write_Byte(0x0C, 0x00);
- 366 1 aa=AS7341_Write_Byte(0x0D, 0x00);
- 367 1 aa=AS7341_Write_Byte(0x0E, 0x24);
- 368 1 aa=AS7341_Write_Byte(0x0F, 0x00);
- 369 1 aa=AS7341_Write_Byte(0x10, 0x00);
- 370 1 aa=AS7341_Write_Byte(0x11, 0x50);
- 371 1 aa=AS7341_Write_Byte(0x12, 0x00);
- 372 1 aa=AS7341_Write_Byte(0x13, 0x06);
- 373 1 }
- 374 ///******************************************************************************
- 375 //function: Configure SMUX for flicker detection
- 376 //info:
- 377 //******************************************************************************/
- 378 void FDConfig()
- 379 {
- 380 1 UBYTE aa;
- 381 1 aa=AS7341_Write_Byte(0x00, 0x00);
- 382 1 aa=AS7341_Write_Byte(0x01, 0x00);
- 383 1 aa=AS7341_Write_Byte(0x02, 0x00);
- 384 1 aa=AS7341_Write_Byte(0x03, 0x00);
- 385 1 aa=AS7341_Write_Byte(0x04, 0x00);
- 386 1 aa=AS7341_Write_Byte(0x05, 0x00);
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 7
- 387 1 aa=AS7341_Write_Byte(0x06, 0x00);
- 388 1 aa=AS7341_Write_Byte(0x07, 0x00);
- 389 1 aa=AS7341_Write_Byte(0x08, 0x00);
- 390 1 aa=AS7341_Write_Byte(0x09, 0x00);
- 391 1 aa=AS7341_Write_Byte(0x0A, 0x00);
- 392 1 aa=AS7341_Write_Byte(0x0B, 0x00);
- 393 1 aa=AS7341_Write_Byte(0x0C, 0x00);
- 394 1 aa=AS7341_Write_Byte(0x0D, 0x00);
- 395 1 aa=AS7341_Write_Byte(0x0E, 0x00);
- 396 1 aa=AS7341_Write_Byte(0x0F, 0x00);
- 397 1 aa=AS7341_Write_Byte(0x10, 0x00);
- 398 1 aa=AS7341_Write_Byte(0x11, 0x00);
- 399 1 aa=AS7341_Write_Byte(0x12, 0x00);
- 400 1 aa=AS7341_Write_Byte(0x13, 0x60);
- 401 1 }
- 402
- 403 ///******************************************************************************
- 404 //function: Start the measurement
- 405 //info: This function only handles SPM and SYNS modes.
- 406 //******************************************************************************/
- 407 void AS7341_startMeasure(eChChoose_t mode)
- 408 {
- 409 1 UBYTE aa,data0 = 0;
- 410 1 data0 = AS7341_Read_Byte(AS7341_CFG_0);
- 411 1 data0 = data0 & (~(1 << 4));
- 412 1
- 413 1 aa=AS7341_Write_Byte(AS7341_CFG_0, data0);
- 414 1
- 415 1 AS7341_EnableSpectralMeasure(false);
- 416 1 aa=AS7341_Write_Byte(0xAF, 0x10); // SMUX Command config
- 417 1
- 418 1 if (mode == eF1F4ClearNIR)
- 419 1 F1F4_Clear_NIR();
- 420 1 else if (mode == eF5F8ClearNIR)
- 421 1 F5F8_Clear_NIR();
- 422 1 AS7341_EnableSMUX(true);
- 423 1 // if (measureMode == eSyns)
- 424 1 // {
- 425 1 // AS7341_SetGpioMode(INPUT);
- 426 1 // AS7341_Config(eSyns);
- 427 1 // }
- 428 1 // else if (measureMode == eSpm)
- 429 1 // {
- 430 1 // AS7341_Config(eSpm);
- 431 1 // }
- 432 1 // AS7341_EnableSpectralMeasure(true);
- 433 1 // if (measureMode == eSpm)
- 434 1 // {
- 435 1 // while (!AS7341_MeasureComplete())
- 436 1 // {
- 437 1 // // DEV_Delay_ms(1);
- 438 1 // //////////////////////////vTaskDelay(1 / portTICK_PERIOD_MS);
- 439 1 // }
- 440 1 // }
- 441 1 }
- 442 ///******************************************************************************
- 443 //function: read flicker data
- 444 //info:
- 445 //******************************************************************************/
- 446 UBYTE AS7341_ReadFlickerData()
- 447 {
- 448 1 UBYTE flicker;
- 449 1 UBYTE aa,data0 = 0;
- 450 1 UBYTE retry = 100;
- 451 1
- 452 1 data0 = AS7341_Read_Byte(AS7341_CFG_0);
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 8
- 453 1 data0 = data0 & (~(1 << 4));
- 454 1 aa=AS7341_Write_Byte(AS7341_CFG_0, data0);
- 455 1 AS7341_EnableSpectralMeasure(false);
- 456 1 aa=AS7341_Write_Byte(0xAF, 0x10);
- 457 1 FDConfig();
- 458 1 AS7341_EnableSMUX(true);
- 459 1 AS7341_EnableSpectralMeasure(true);
- 460 1 // AS7341_Write_Byte(0xDA,0x00);
- 461 1
- 462 1 if (retry == 0)
- 463 1 //printf(" data access error");
- 464 1 AS7341_EnableFlickerDetection(true);
- 465 1 // DEV_Delay_ms(600);
- 466 1 //////////////////////////vTaskDelay(600 / portTICK_PERIOD_MS);
- 467 1 flicker = AS7341_Read_Byte(AS7341_STATUS);
- 468 1 //printf("flicker: %d \r\n", flicker);
- 469 1 AS7341_EnableFlickerDetection(false);
- 470 1 switch (flicker)
- 471 1 {
- 472 2 case 37:
- 473 2 flicker = 100;
- 474 2 break;
- 475 2 case 40:
- 476 2 flicker = 0;
- 477 2 break;
- 478 2 case 42:
- 479 2 flicker = 120;
- 480 2 break;
- 481 2 case 44:
- 482 2 flicker = 1;
- 483 2 break;
- 484 2 case 45:
- 485 2 flicker = 2;
- 486 2 break;
- 487 2 default:
- 488 2 flicker = 2;
- 489 2 }
- 490 1 return flicker;
- 491 1 }
- 492
- 493 ///******************************************************************************
- 494 //function: Determine whether the measurement is complete
- 495 //info:
- 496 //******************************************************************************/
- 497
- 498 int AS7341_MeasureComplete()
- 499 {
- 500 1 UBYTE status;
- 501 1 status = AS7341_Read_Byte(AS7341_STATUS_2);
- 502 1 if ((status & (1 << 6)))
- 503 1 {
- 504 2 return true;
- 505 2 }
- 506 1 else
- 507 1 {
- 508 2 return false;
- 509 2 }
- 510 1 }
- 511
- 512 ///******************************************************************************
- 513 //function: Gets data for all channels
- 514 //info:
- 515 //******************************************************************************/
- 516 UWORD AS7341_GetChannelData(UBYTE channel)
- 517 {
- 518 1 UWORD data0[2];
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 9
- 519 1 UWORD channelData = 0x0000;
- 520 1 data0[0] = AS7341_Read_Byte(AS7341_CH0_DATA_L + channel * 2);
- *** WARNING C188 IN LINE 520 OF AS7341.c: 'parameter 1': value truncated
- 521 1 data0[1] = AS7341_Read_Byte(AS7341_CH0_DATA_H + channel * 2);
- *** WARNING C188 IN LINE 521 OF AS7341.c: 'parameter 1': value truncated
- 522 1 channelData = data0[1];
- 523 1 channelData = (channelData << 8) | data0[0];
- 524 1 // DEV_Delay_ms(50);
- 525 1 /////////////////////////////vTaskDelay(50 / portTICK_PERIOD_MS);
- 526 1 return channelData;
- 527 1 }
- 528
- 529 ///******************************************************************************
- 530 //function: Use SMUX to read data from the low channel
- 531 //info:
- 532 //******************************************************************************/
- 533
- 534 //sModeOneData_t AS7341_ReadSpectralDataOne()
- 535 //{
- 536 // sModeOneData_t data;
- 537 // data.channel1 = AS7341_GetChannelData(0);
- 538 // data.channel2 = AS7341_GetChannelData(1);
- 539 // data.channel3 = AS7341_GetChannelData(2);
- 540 // data.channel4 = AS7341_GetChannelData(3);
- 541 // data.CLEAR = AS7341_GetChannelData(4);
- 542 // data.NIR = AS7341_GetChannelData(5);
- 543 // return data;
- 544 //}
- 545
- 546 ///******************************************************************************
- 547 //function: Use SMUX to read data from the high channel
- 548 //info:
- 549 //******************************************************************************/
- 550
- 551 //sModeTwoData_t AS7341_ReadSpectralDataTwo()
- 552 //{
- 553 // sModeTwoData_t data0;
- 554 // data0.channel5 = AS7341_GetChannelData(0);
- 555 // data0.channel6 = AS7341_GetChannelData(1);
- 556 // data0.channel7 = AS7341_GetChannelData(2);
- 557 // data0.channel8 = AS7341_GetChannelData(3);
- 558 // data0.CLEAR = AS7341_GetChannelData(4);
- 559 // data0.NIR = AS7341_GetChannelData(5);
- 560 // return data0;
- 561 //}
- 562
- 563 ///******************************************************************************
- 564 //function: Set GPIO to input or output mode
- 565 //info:
- 566 //******************************************************************************/
- 567 void AS7341_SetGpioMode(UBYTE mode)
- 568 {
- 569 1 UBYTE data0,aa;
- 570 1
- 571 1 data0 = AS7341_Read_Byte(AS7341_GPIO_2);
- 572 1 if (mode == INPUT)
- 573 1 {
- 574 2 data0 = data0 | (1 << 2);
- 575 2 }
- 576 1
- 577 1 if (mode == OUTPUT)
- 578 1 {
- 579 2 data0 = data0 & (~(1 << 2));
- 580 2 }
- 581 1 aa=AS7341_Write_Byte(AS7341_GPIO_2, data0);
- 582 1 }
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 10
- 583
- 584 ///******************************************************************************
- 585 //function: Configure the ATIME register
- 586 //info:
- 587 //******************************************************************************/
- 588 void AS7341_ATIME_config(UBYTE value)
- 589 {
- 590 1 UBYTE aa;
- 591 1 aa=AS7341_Write_Byte(AS7341_ATIME, value);
- 592 1 }
- 593
- 594 ///******************************************************************************
- 595 //function: Configure the ASTEP register
- 596 //info:
- 597 //******************************************************************************/
- 598 void AS7341_ASTEP_config(UWORD value)
- 599 {
- 600 1 UBYTE highValue, lowValue,aa;
- 601 1 lowValue = value & 0x00ff;
- 602 1 highValue = value >> 8;
- 603 1 aa=AS7341_Write_Byte(AS7341_ASTEP_L, lowValue);
- 604 1 aa=AS7341_Write_Byte(AS7341_ASTEP_H, highValue);
- 605 1 }
- 606
- 607 ///******************************************************************************
- 608 //function: Configure the AGAIN register
- 609 //value: 0 1 2 3 4 5 6 7 8 9 10
- 610 //gain: X0.5 | X1 | X2 | X4 | X8 | X16 | X32 | X64 | X128 | X256 | X512
- 611 //******************************************************************************/
- 612 void AS7341_AGAIN_config(UBYTE value)
- 613 {
- 614 1 UBYTE aa;
- 615 1 if (value > 10)
- 616 1 value = 10;
- 617 1 aa=AS7341_Write_Byte(AS7341_CFG_1, value);
- 618 1 }
- 619
- 620 ///******************************************************************************
- 621 //function: enable led
- 622 //info:true : Enable
- 623 // false : Anergy
- 624 //******************************************************************************/
- 625 void AS7341_EnableLED(int flag)
- 626 {
- 627 1 UBYTE aa,data0 = 0;
- 628 1 UBYTE data1 = 0;
- 629 1 AS7341_SetBank(1);
- 630 1 data0 = AS7341_Read_Byte(AS7341_CONFIG);
- 631 1 data1 = AS7341_Read_Byte(AS7341_LED);
- 632 1 if (flag == true)
- 633 1 {
- 634 2 data0 = data0 | 0x08;
- 635 2 }
- 636 1 else
- 637 1 {
- 638 2 data0 = data0 & 0xf7;
- 639 2 data1 = data1 & 0x7f;
- 640 2 aa=AS7341_Write_Byte(AS7341_LED, data1);
- 641 2 }
- 642 1 aa=AS7341_Write_Byte(AS7341_CONFIG, data0);
- 643 1 AS7341_SetBank(0);
- 644 1 }
- 645 ///******************************************************************************
- 646 //function: set REG_BANK
- 647 //info: 0: Register access to register 0x80 and above
- 648 // 1: Register access to register 0x60 to 0x74
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 11
- 649 //******************************************************************************/
- 650 void AS7341_SetBank(UBYTE addr)
- 651 {
- 652 1 UBYTE aa,data0 = 0;
- 653 1 data0 = AS7341_Read_Byte(AS7341_CFG_0);
- 654 1 if (addr == 1)
- 655 1 {
- 656 2
- 657 2 data0 = data0 | (1 << 4);
- 658 2 }
- 659 1
- 660 1 if (addr == 0)
- 661 1 {
- 662 2
- 663 2 data0 = data0 & (~(1 << 4));
- 664 2 }
- 665 1 aa=AS7341_Write_Byte(AS7341_CFG_0, data0);
- 666 1 }
- 667 ///******************************************************************************
- 668 //function: Control the brightness of the LED
- 669 //info: LED : true : LED ON
- 670 // false : LED OFF
- 671 // current : intensity control
- 672 //******************************************************************************/
- 673 void AS7341_ControlLed(UBYTE LED, UBYTE current)
- 674 {
- 675 1 UBYTE aa,data0 = 0;
- 676 1 if (current < 1)
- 677 1 current = 1;
- 678 1 current--;
- 679 1 if (current > 19)
- 680 1 current = 19;
- 681 1 AS7341_SetBank(1);
- 682 1 if (LED == true)
- 683 1 data0 = 0x80 | current;
- 684 1 else
- 685 1 data0 = current;
- 686 1 aa=AS7341_Write_Byte(AS7341_LED, data0);
- 687 1 // DEV_Delay_ms(100);
- 688 1 /////////////////////////vTaskDelay(100 / portTICK_PERIOD_MS);
- 689 1 AS7341_SetBank(0);
- 690 1 }
- 691
- 692 ///******************************************************************************
- 693 //function: Determine whether the threshold setting is exceeded
- 694 //info:Spectral interruptions occur when the set threshold is exceeded
- 695 //******************************************************************************/
- 696 void AS7341_INTerrupt()
- 697 {
- 698 1 UBYTE data0 = AS7341_Read_Byte(AS7341_STATUS_1);
- 699 1 if (data0 & 0x80)
- 700 1 {
- 701 2 //printf("Spectral interrupt generation !\r\n");
- 702 2 }
- 703 1 else
- 704 1 {
- 705 2 return;
- 706 2 }
- 707 1 }
- 708
- 709 ///******************************************************************************
- 710 //function: clear interrupt
- 711 //info: This register is self-clearing, meaning that writing a "1" to any bit in the
- 712 // register clears that status bit.
- 713 //******************************************************************************/
- 714 void AS7341_ClearInterrupt()
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 12
- 715 {
- 716 1 UBYTE aa;
- 717 1 aa=AS7341_Write_Byte(AS7341_STATUS_1, 0xff);
- 718 1 }
- 719 ///******************************************************************************
- 720 //function: enable spectral interrupt
- 721 //info:
- 722 //******************************************************************************/
- 723 void AS7341_EnableSpectralInterrupt(int flag)
- 724 {
- 725 1 UBYTE data0,aa;
- 726 1 data0 = AS7341_Read_Byte(AS7341_INTENAB);
- 727 1 if (flag == true)
- 728 1 {
- 729 2 data0 = data0 | (1 << 3);
- 730 2 aa=AS7341_Write_Byte(AS7341_INTENAB, data0);
- 731 2 }
- 732 1 else
- 733 1 {
- 734 2 data0 = data0 & (~(1 << 3));
- 735 2 aa=AS7341_Write_Byte(AS7341_INTENAB, data0);
- 736 2 }
- 737 1 }
- 738 ///******************************************************************************
- 739 //function:Spectral Interrupt Persistence
- 740 // value: CHANNEL:
- 741 // 0 Every spectral cycle generates aninterrupt
- 742 // 1 1
- 743 // 2 2
- 744 // 3 3
- 745 // 4 5
- 746 // 5 10
- 747 // ... 5*(value-3)
- 748 // 14 55
- 749 // 15 60
- 750 //******************************************************************************/
- 751 void AS7341_SetInterruptPersistence(UBYTE value)
- 752 {
- 753 1 UBYTE data0,aa;
- 754 1 data0 = value;
- 755 1 aa=AS7341_Write_Byte(AS7341_PERS, data0);
- 756 1 data0 = AS7341_Read_Byte(AS7341_PERS);
- 757 1 }
- 758 ///******************************************************************************
- 759 //function: Set the interrupt threshold up and
- 760 //info:
- 761 //******************************************************************************/
- 762 void AS7341_SetThreshold(UWORD lowThre, UWORD highThre)
- 763 {
- 764 1 UBYTE aa;
- 765 1
- 766 1 if (lowThre >= highThre)
- 767 1 return;
- 768 1 else
- 769 1
- 770 1 aa=AS7341_Write_Byte(AS7341_SP_TH_L_LSB, lowThre);
- *** WARNING C188 IN LINE 770 OF AS7341.c: 'parameter 2': value truncated
- 771 1
- 772 1 aa=AS7341_Write_Byte(AS7341_SP_TH_L_MSB, lowThre >> 8);
- *** WARNING C188 IN LINE 772 OF AS7341.c: 'parameter 2': value truncated
- 773 1
- 774 1 aa=AS7341_Write_Byte(AS7341_SP_TH_H_LSB, highThre);
- *** WARNING C188 IN LINE 774 OF AS7341.c: 'parameter 2': value truncated
- 775 1 aa=AS7341_Write_Byte(AS7341_SP_TH_H_MSB, highThre >> 8);
- *** WARNING C188 IN LINE 775 OF AS7341.c: 'parameter 2': value truncated
- 776 1
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 13
- 777 1 // DEV_Delay_ms(20);
- 778 1 //////////////////////////////vTaskDelay(20 / portTICK_PERIOD_MS);
- 779 1 }
- 780 ///******************************************************************************
- 781 //function: Set the Spectral Threshold Channel
- 782 // VALUE CHANNEL
- 783 // 0 CH0
- 784 // 1 CH1
- 785 // 2 CH2
- 786 // 3 CH3
- 787 // 4 CH4
- 788 //******************************************************************************/
- 789 void AS7341_SetSpectralThresholdChannel(UBYTE value)
- 790 {
- 791 1 UBYTE aa;
- 792 1 aa=AS7341_Write_Byte(AS7341_CFG_12, value);
- 793 1 }
- 794
- 795 ///******************************************************************************
- 796 //function: get low threshold
- 797 //info:
- 798 //******************************************************************************/
- 799
- 800 UWORD AS7341_GetLowThreshold()
- 801 {
- 802 1 UWORD data0;
- 803 1 data0 = AS7341_Read_Byte(AS7341_SP_TH_L_LSB);
- 804 1 data0 = (AS7341_Read_Byte(AS7341_SP_TH_L_MSB) << 8) | data0;
- 805 1 return data0;
- 806 1 }
- 807
- 808 ///******************************************************************************
- 809 //function: get high threshold
- 810 //info:
- 811 //******************************************************************************/
- 812 UWORD AS7341_GetHighThreshold()
- 813 {
- 814 1 UWORD data0;
- 815 1 data0 = AS7341_Read_Byte(AS7341_SP_TH_H_LSB);
- 816 1 data0 = (AS7341_Read_Byte(AS7341_SP_TH_H_MSB) << 8) | data0;
- 817 1 return data0;
- 818 1 }
- 819
- 820 ///******************************************************************************
- 821 //function: syns interrupt set
- 822 //info:
- 823 //******************************************************************************/
- 824 void AS7341_SynsINT_sel()
- 825 {
- 826 1 UBYTE aa;
- 827 1 aa=AS7341_Write_Byte(AS7341_CONFIG, 0x05);
- 828 1 }
- 829
- 830 ///******************************************************************************
- 831 //function: disable power,spectral reading, flicker detection
- 832 //info:
- 833 //******************************************************************************/
- 834 void AS7341_disableALL()
- 835 {
- 836 1 UBYTE aa;
- 837 1 aa=AS7341_Write_Byte(AS7341_ENABLE, 0x02);
- 838 1 }
- 839
- Module Information Static Overlayable
- ------------------------------------------------
- C251 COMPILER V5.60.0, AS7341 03/12/24 17:22:31 PAGE 14
- code size = 1637 ------
- ecode size = ------ ------
- data size = ------ ------
- idata size = ------ ------
- pdata size = ------ ------
- xdata size = ------ ------
- xdata-const size = ------ ------
- edata size = 2 4
- bit size = ------ 1
- ebit size = ------ ------
- bitaddressable size = ------ ------
- ebitaddressable size = ------ ------
- far data size = ------ ------
- huge data size = ------ ------
- const size = ------ ------
- hconst size = ------ ------
- End of Module Information.
- C251 COMPILATION COMPLETE. 7 WARNING(S), 0 ERROR(S)
|