from: https://blog.csdn.net/hgkhjkljnl/article/details/136140478 빅가이의 오픈소스인 STM32H750VB/H7B0VB 코어보드를 복사했는데, 아톰스크린과 호환이 되지만, 직접 구매하기엔 가격이 너무 비싸서 버전을 그려봤습니다. 모든 리소스( 개발 보드 정보, 학습에 사용할 수 있는 지원 프로세스): 링크: https://pan.baidu.com/s/1rnQgIgXpFH0-jDEgN7raPA?pwd=szz7 추출 코드: […]
개요 리포트 아이템 • 블루투스 5.0:최신 블루투스 5.0 기술로 원활한 연결을 통해 오디오 신호의 안정적이고 빠른 전송을 보장합니다. • 고출력 오디오:고품질 오디오 재생에 완벽한 2X50W 의 최대 출력 전력으로 강력하고 […]
사전 준비 OpenMediaVault 7이 설치되어 있어야 합니다. Docker와 Docker Compose가 설치되어 있어야 합니다. 설치 단계 SSH를 통해 OpenMediaVault 서버에 접속합니다. (ssh root@omv-ip) Immich 설치를 위한 디렉토리를 생성합니다:
1 2 3 4 |
mkdir -p /srv/dev-disk-by-uuid-[your-disk-uuid]/docker/immich cd /srv/dev-disk-by-uuid-[your-disk-uuid]/docker/immich |
Immich의 docker-compose.yml […]
link / 11,550 /9k
link
출처: https://rs29.tistory.com/13 사용한 MAX7219 7-sement 모듈 통신 방법 : SPI (최대속도 : 10Mhz) 작동 전압 : 4.0~5.5 환경 : P-NUCLEO-WB55 개발 보드, Atollic TrueSTUDIO [동작] 16 비트 데이터 […]
from: https://ynformatics.com/2022/low-cost-8-port-serial-to-ethernet-server/ I needed to connect some more test equipment to my LAN. Currently this is done with individual Serial-to-Ethernet adapters in takeaway curry containers but this was getting ungainly […]
https://windowsforum.kr/lecture/20874606 안녕하세요? 같은 내용을 예전에 올렸습니다. https://windowsforum.kr/lecture/17680459 최근 좀 더 개선하여서 올려봅니다.^^ 다음과 같은 꼭 필요한 사항이 고려되어야 할 것 같습니다. – 사용자 권한이나 관리자 권한에서 실행시 오류 없을 것 – […]
출처: https://venusgirls.tistory.com/entry/madVR-%EC%98%81%EC%83%81-%EC%B2%98%EB%A6%AC-%EB%A0%8C%EB%8D%94%EB%9F%AC-%ED%95%9C%EA%B8%80 동영상을 재생할 때 화면을 왜곡하거나 화질에 해를 끼치는 그래픽카드 자체의 로직은 차단(bypass)하고, 동시에 그래픽카드의 물리적인 성능은 최대한 활용해서, 화질에 이로운 고품질의 후처리를 통해 영상이 원래 의도한 화면을 최대한 […]
출처: https://windowsforum.kr/index.php?mid=data&search_keyword=LAVFilters&search_target=title_content&document_srl=20598062 LAV 필터는 ffmpeg 프로젝트의 libavformat 및 libavcodec 라이브러리를 기반으로 한 DirectShow 필터 세트로, DirectShow 플레이어에서 거의 모든 형식을 재생할 수 있습니다. 필터는 아직 개발 중이므로 모든 기능이 […]
Core: Arm® 32-bit Cortex®-M0+ CPU, frequency up to 64 MHz -40°C to 85°C/105°C/125°C operating temperature Memories Up to 64 Kbytes of Flash memory with protection and securable area 8 Kbytes of […]
https://github.com/WeActStudio/WeActStudio.STM32F4_64Pin_CoreBoard?tab=readme-ov-file WeActStudio.STM32F4_64Pin_CoreBoard-master STM32F405RGT6 (10,202) Freq:168Mhz Max RAM:192KB,ROM:1MB STM32F412RET6 (6,988) Freq:100Mhz Max RAM:256KB,ROM:512KB STM32F446RET6 (8,168) Freq:180Mhz Max RAM:128KB,ROM:512KB
https://ko.aliexpress.com/item/1005007133350270.html?spm=a2g0o.cart.0.0.38cb56balTdch8&mp=1&gatewayAdapt=glo2kor https://github.com/WeActStudio/WeActStudio.EpaperModule WeActStudio.EpaperModule-master
Aliexpress Link (19,735) https://github.com/WeActStudio/MiniSTM32H7xx.git MiniSTM32H7xx-master STM32H7xx Core Board 0.96'' ST7735 TFT, TF Card, 8MB SPI FLASH(SPI1), 8MB QSPI FLASH(QSPI1), 8Bit DVP Port support openmv firmware, see SDK/openmv STM32H750VBT6 128KB ROM, 1MB […]
driver download: https://github.com/peckishrine/aic8800_windows_drivers?tab=readme-ov-file AIC8800D80_wifi6, Fenvi(Fenvi WIFI 6 AX286) https://ko.aliexpress.com/item/1005005744406270.html?spm=a2g0o.order_list.order_list_main.82.5c7f140fYoe1DF&gatewayAdapt=glo2kor FENVI WIFI 6 어댑터 AX286 네트워크 카드 미니 USB 동글 2.4GHz 802.11AX 신호 수신 PC 노트북 윈도우 10/11 드라이버 무료 • […]
자신이 경험해 보지 못한 것들을 우리는 영화나 책에서 접한다… 그런데 왜? 그것을 (일반적이거나, 보편적인것, 객관적인 것, 상식적인 것) 거져 얻는 그것을, 고통과 금전과 시간과 공간을 뛰어넘는 그것을, 그 고마운것을 우리는 […]
EPSON_V10_LQ-590HII_LQ-2090HII User Manual
출처: https://coolenjoy.net/bbs/overclock/850632 그동안 5800X 에 비해 가격도 큰차이가 없어 가성비 최악에 인기 없는 제품이 5700X 입니다. 저렴한 가격에 구입하게 되어 가성비가 확보되기에 진행하려 했는데 인기 없다보니 정보가 너무 부실하더군요. 그래서 […]
출처: https://m.blog.naver.com/kiatwins/221124103717 CubeMX로 아두이노 D5~7번 3개의 핀을 출력으로 설정하고 프로젝트를 생성하고 아래 코드를 넣어주면 됩니다. 시간설정은 터미널에서 년월일시분초 12자를 입력하면 수신인터럽트로 처리해서 RTC 레지스터에 저장이 됩니다. stm32f1xxit.c에 있는 USART2_IRQHandler 함수는 지우거나 […]
출처: https://uptimefab.com/2021/01/11/build-your-own-cnc-controller/ Introduction In this article I will go through the entire build process for an offline CNC controller that I have made for my 6040 CNC router. Although it […]
mariadb-10.6.16-winx64
HeidiSQL_12.6_32_Portable
아래 코드는 복사 및 삭제입니다(원시 이동 또는 이름 바꾸기 대신). [Code]이 논리를 구현하려면 섹션을 사용하세요 . 지원되는 기능 과 처리할 수 있는 이벤트 에 대한 문서는 꽤 좋습니다. 설치 시작 시 대응 방법:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
procedure CurStepChanged(CurStep: TSetupStep); begin case CurStep of ssInstall: begin { will be executed just before the actual installation starts } end; ssPostInstall: begin { will be executed just after the actual installation finishes } end; end; end; |
파일이 […]
from: https://eroro.tistory.com/591 NTC의 특성 값이나 회로 부분은 변경하여 사용하여야 합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#define REF_RESIST 10000 #define VREF 3.3f /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : 3.3 : 4096 = x : ADC Vout= (x/(x+10000)) * 3.3 *******************************************************************************/ float Calculation_Vout(u16 a_nhADCValue, u8 a_chComp) { float Vout, Resistor; a_nhADCValue += a_chComp; Vout = (a_nhADCValue * VREF); Vout /= 4095; // DEBUGPRINT("ADC Vout %f, ", Vout); Resistor = Vout *(REF_RESIST/(VREF-Vout)); // DEBUGPRINT("Resistor %f\r\n", Resistor); return Resistor; } #define REF_LDTEMP_BETA 3477 #define REF_LDTEMP_BETA_REVERSE 0.000288 //1/REF_LDTEMP_BETA #define REF_LDTEMP_25 298.15f #define REF_LDTEMP_K 273.15f #define REF_LDTEMP_UPPERRESIS 10000 /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None 0 Degree Resistor = 10000*exp((REF_LDTEMP_BETA*((1/REF_LDTEMP_K)-(1/REF_LDTEMP_25)))); Resistor = 290776.77 Ohm *******************************************************************************/ u16 ADC_LDTemperature_Calc(u16 ADC_Batt, u8 ADC_Compensation) { float Resistor, Celsius; Resistor = Calculation_Vout(ADC_Batt, 0); Celsius = (REF_LDTEMP_BETA_REVERSE*log(Resistor/REF_LDTEMP_UPPERRESIS)); // DEBUGPRINT("Celsius %f\r\n", Celsius); Celsius += (1/REF_LDTEMP_25); // DEBUGPRINT("Celsius %f\r\n", Celsius); Celsius = pow(Celsius, -1); // DEBUGPRINT("Celsius %f\r\n", Celsius); Celsius -= 273.15f; // DEBUGPRINT("Celsius %f\r\n", Celsius); if(Celsius < 0) Celsius = 0; return (u16)Celsius; } |
from: https://eroro.tistory.com/600 PF0, PF1을 사용하기 위해 RCC_DeInit함수 사용
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/* For PF0, PF1 */ RCC_DeInit(); GPIO_InitTypeDef GPIO_InitStruct; // AFIO_REMAP_ENABLE(AFIO_MAPR_PD01_REMAP); /* Enable GPIOF clock */ RCC_AHBPeriphClockCmd(PERI_BUTTON, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); GPIO_InitStruct.GPIO_Pin = PIN_BUTTON_0 | PIN_BUTTON_1; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd_UP; //GPIO_Mode_IPU; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(PORT_BUTTON, &GPIO_InitStruct); while(1){ if (GPIO_ReadInputDataBit(PORT_BUTTON, PIN_BUTTON_0) != SET) {/* Forward */ DEBUGPRINT("BTN0\r\n"); } if (GPIO_ReadInputDataBit(PORT_BUTTON, PIN_BUTTON_1) != SET) {/* Forward */ DEBUGPRINT("BTN1\r\n"); } GPIO_ToggleBit(PORT_LED, PIN_LED_0); GPIO_ToggleBit(PORT_LED, PIN_LED_1); Delay(100); } |
from: https://eroro.tistory.com/601 Remote 16-bit I/O expander for I2C-bus 테스트 프로그램 PIN 7에서 PIN 10번으로 넘어가는 부분을 PIN 8번으로 작성하였습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
/************************** (C) COPYRIGHT 2023 ***************** * File Name : * Author : * Version : Ver 0.1 * Date : 2023/03/15 * Description : * * Revision History * Date Version Name Description 2023/03/15 0.1 Oanny Proto. *******************************************************************************/ #ifndef __USR_I2C_H #define __USR_I2C_H #include "stm32f10x.h" #include "usr_system.h" /* ADDR : 0100 A2 A1 A0 RW */ #define PCF8575_ADDRESS 0x40 /* DATA DIR => 0100 A2 A1 A0 RW (ACK) P07 P06 P05 P04 P03 P02 P01 P00 (ACK) P17 P16 P15 P14 P13 P12 P11 P00 (ACK) */ #define I2C_Speed 100000 #define I2C_1 1 #define I2C_2 2 /* BASE : 0100 A2 A1 A0 RW (ACK) P07 P06 P05 P04 P03 P02 P01 P00 (ACK) P17 P16 P15 P14 P13 P12 P11 P00 (ACK) READ : 0100 A2 A1 A0 0 (ACK) P07 P06 P05 P04 P03 P02 P01 P00 (ACK) P17 P16 P15 P14 P13 P12 P11 P00 (ACK) WRITE : 0100 A2 A1 A0 1 (ACK) P07 P06 P05 P04 P03 P02 P01 P00 (ACK) P17 P16 P15 P14 P13 P12 P11 P00 (ACK) */ #define PCF8575_Pin_0 ((uint8_t)0x0001) /*!< Pin 0 selected */ #define PCF8575_Pin_1 ((uint8_t)0x0002) /*!< Pin 1 selected */ #define PCF8575_Pin_2 ((uint8_t)0x0004) /*!< Pin 2 selected */ #define PCF8575_Pin_3 ((uint8_t)0x0008) /*!< Pin 3 selected */ #define PCF8575_Pin_4 ((uint8_t)0x0010) /*!< Pin 4 selected */ #define PCF8575_Pin_5 ((uint8_t)0x0020) /*!< Pin 5 selected */ #define PCF8575_Pin_6 ((uint8_t)0x0040) /*!< Pin 6 selected */ #define PCF8575_Pin_7 ((uint8_t)0x0080) /*!< Pin 7 selected */ #define PCF8575_Pin_8 ((uint16_t)0x0100) /*!< Pin 8 selected */ #define PCF8575_Pin_9 ((uint16_t)0x0200) /*!< Pin 9 selected */ #define PCF8575_Pin_10 ((uint16_t)0x0400) /*!< Pin 10 selected */ #define PCF8575_Pin_11 ((uint16_t)0x0800) /*!< Pin 11 selected */ #define PCF8575_Pin_12 ((uint16_t)0x1000) /*!< Pin 12 selected */ #define PCF8575_Pin_13 ((uint16_t)0x2000) /*!< Pin 13 selected */ #define PCF8575_Pin_14 ((uint16_t)0x4000) /*!< Pin 14 selected */ #define PCF8575_Pin_15 ((uint16_t)0x8000) /*!< Pin 15 selected */ #define PCF8575_Pin_All ((uint16_t)0xFFFF) /*!< All pins selected */ void I2C_Config(uint8_t i2c, uint32_t speed); void I2C2_ByteWrite(uint16_t a_DeviceAddr, uint8_t* pBuffer); void I2C2_BufferRead(uint16_t a_DeviceAddr, uint8_t* pBuffer, uint16_t NumByteToRead); void PCF8575_Demo(void); #endif |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
/************************** (C) COPYRIGHT 2023 ***************** * File Name : * Author : * Version : Ver 0.1 * Date : 2023/03/15 * Description : * * Revision History * Date Version Name Description 2023/03/15 0.1 Oanny Proto. *******************************************************************************/ #include <stdarg.h> #include <stdio.h> #include <string.h> #include "usr_i2c.h" #include "usr_uart.h" /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro ------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes ------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ #if 0 typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus; /******************************************************************************* * Function Name : * Parameters : * Return : none * Description : *******************************************************************************/ TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength) { while(BufferLength--) { if(*pBuffer1 != *pBuffer2) { return FAILED; } pBuffer1++; pBuffer2++; } return PASSED; } #endif /******************************************************************************* * Function Name : * Parameters : * Return : none * Description : - I2C2 - PB10 EN PB11 FREQ I2C_Config(I2C_1, I2C_Speed); *******************************************************************************/ void I2C_Config(uint8_t i2c, uint32_t speed) { GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_InitStructure; if(i2c == I2C_1){ /* I2C Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); /* GPIO Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* Configure I2C1 pins: SCL and SDA */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB, &GPIO_InitStructure); /* I2C configuration */ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = PCF8575_ADDRESS; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = speed; /* I2C Peripheral Enable */ I2C_Cmd(I2C1, ENABLE); /* Apply I2C configuration after enabling it */ I2C_Init(I2C1, &I2C_InitStructure); } else if(i2c == I2C_2){ /* I2C Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); /* GPIO Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* Configure I2C2 pins: SCL and SDA */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB, &GPIO_InitStructure); /* I2C configuration */ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = PCF8575_ADDRESS; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = speed; /* I2C Peripheral Enable */ I2C_Cmd(I2C2, ENABLE); /* Apply I2C configuration after enabling it */ I2C_Init(I2C2, &I2C_InitStructure); } } #define I2C_TIMEOUT 0x100000 /******************************************************************************* * Function Name : * Parameters : * Return : none * Description : *******************************************************************************/ void I2C2_ByteWrite(uint16_t a_DeviceAddr, uint8_t* pBuffer) { uint32_t I2C_Timeout = I2C_TIMEOUT; /* Send STRAT condition */ I2C_GenerateSTART(I2C2, ENABLE); /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send EEPROM address for write */ I2C_Send7bitAddress(I2C2, a_DeviceAddr, I2C_Direction_Transmitter); I2C_Timeout = I2C_TIMEOUT; /* Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send the byte to be written */ I2C_SendData(I2C2, pBuffer[0]); I2C_Timeout = I2C_TIMEOUT; /* Test on EV8 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send the byte to be written */ I2C_SendData(I2C2, pBuffer[1]); I2C_Timeout = I2C_TIMEOUT; /* Test on EV8 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send STOP condition */ I2C_GenerateSTOP(I2C2, ENABLE); } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None *******************************************************************************/ void I2C2_ByteRead(uint16_t a_DeviceAddr, uint8_t* pBuffer, uint16_t NumByteToRead) { uint32_t I2C_Timeout = I2C_TIMEOUT; /* While the bus is busy */ while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send STRAT condition a second time */ I2C_GenerateSTART(I2C2, ENABLE); I2C_Timeout = I2C_TIMEOUT; /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send EEPROM address for read */ I2C_Send7bitAddress(I2C2, a_DeviceAddr, I2C_Direction_Receiver); I2C_Timeout = I2C_TIMEOUT; /* Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* While there is data to be read */ while(NumByteToRead) { if(NumByteToRead == 1){ /* Disable Acknowledgement */ I2C_AcknowledgeConfig(I2C2, DISABLE); /* Send STOP Condition */ I2C_GenerateSTOP(I2C2, ENABLE); } /* Test on EV7 and clear it */ if(I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED)){ /* Read a byte from the EEPROM */ *pBuffer = I2C_ReceiveData(I2C2); /* Point to the next location where the byte read will be saved */ pBuffer++; /* Decrement the read bytes counter */ NumByteToRead--; } } /* Enable Acknowledgement to be ready for another reception */ I2C_AcknowledgeConfig(I2C2, ENABLE); } /******************************************************************************* * Function Name : * Parameters : * Return : none * Description : *******************************************************************************/ void I2C2_HalfWordWrite(uint16_t a_DeviceAddr, uint16_t pBuffer) { uint32_t I2C_Timeout = I2C_TIMEOUT; /* Send STRAT condition */ I2C_GenerateSTART(I2C2, ENABLE); /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send EEPROM address for write */ I2C_Send7bitAddress(I2C2, a_DeviceAddr, I2C_Direction_Transmitter); I2C_Timeout = I2C_TIMEOUT; /* Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send the byte to be written */ I2C_SendData(I2C2, (uint8_t)(pBuffer & 0x00FF)); // DEBUGPRINT("W1 %X\r\n", (uint8_t)(pBuffer & 0x00FF)); I2C_Timeout = I2C_TIMEOUT; /* Test on EV8 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send the byte to be written */ I2C_SendData(I2C2, (uint8_t)((pBuffer & 0xFF00) >> 8)); // DEBUGPRINT("W2 %X\r\n", (uint8_t)((pBuffer & 0xFF00) >> 8)); I2C_Timeout = I2C_TIMEOUT; /* Test on EV8 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send STOP condition */ I2C_GenerateSTOP(I2C2, ENABLE); } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None *******************************************************************************/ uint16_t I2C2_HalfWordRead(uint16_t a_DeviceAddr) { uint32_t I2C_Timeout = I2C_TIMEOUT; uint8_t I2C_Buffer[2], Buf_Poi = 0, NumByteToRead; /* While the bus is busy */ while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send STRAT condition a second time */ I2C_GenerateSTART(I2C2, ENABLE); I2C_Timeout = I2C_TIMEOUT; /* Test on EV5 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } /* Send EEPROM address for read */ I2C_Send7bitAddress(I2C2, a_DeviceAddr, I2C_Direction_Receiver); I2C_Timeout = I2C_TIMEOUT; /* Test on EV6 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)){ I2C_Timeout--; if(I2C_Timeout < 1) break; } NumByteToRead = 2; /* While there is data to be read */ while(NumByteToRead) { if(NumByteToRead == 1){ /* Disable Acknowledgement */ I2C_AcknowledgeConfig(I2C2, DISABLE); /* Send STOP Condition */ I2C_GenerateSTOP(I2C2, ENABLE); } /* Test on EV7 and clear it */ if(I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED)){ /* Read a byte from the EEPROM */ I2C_Buffer[Buf_Poi] = I2C_ReceiveData(I2C2); /* Point to the next location where the byte read will be saved */ Buf_Poi++; /* Decrement the read bytes counter */ NumByteToRead--; } } /* Enable Acknowledgement to be ready for another reception */ I2C_AcknowledgeConfig(I2C2, ENABLE); return I2C_Buffer[0] | (I2C_Buffer[1] << 8); } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None *******************************************************************************/ uint8_t PCF8575_ReadInputDataBit(uint16_t GPIO_Pin) { uint8_t bitstatus = 0x00; if ((I2C2_HalfWordRead(PCF8575_ADDRESS) & GPIO_Pin) != (uint32_t)Bit_RESET){ bitstatus = (uint8_t)Bit_SET; } else{ bitstatus = (uint8_t)Bit_RESET; } return bitstatus; } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None *******************************************************************************/ void PCF8575_Demo(void) { I2C_Config(I2C_2, I2C_Speed); while(1){ #if 0 uint8_t i = 0; uint8_t I2C_Buffer[2] = {0, }; if(i == 0){ I2C_Buffer[0] = 0; I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 1){ I2C_Buffer[0] = (uint8_t)GPIO_Pin_0; I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 2){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 3){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 4){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 5){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 6){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 7){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 8){ I2C_Buffer[0] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7); I2C_Buffer[1] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 9){ I2C_Buffer[1] = (uint8_t)GPIO_Pin_0; I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 10){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 11){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 12){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 13){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 14){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 15){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } else if(i == 16){ I2C_Buffer[1] = (uint8_t)(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7); I2C_Buffer[0] = 0; // DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); } GPIO_ToggleBit(GPIOA, GPIO_Pin_3); I2C2_ByteWrite(PCF8575_ADDRESS, I2C_Buffer); delay_ms(500); I2C_Buffer[0] = 0; I2C_Buffer[1] = 0; I2C2_ByteRead(PCF8575_ADDRESS, I2C_Buffer, 2); DEBUGPRINT("%X, %X\r\n", I2C_Buffer[0], I2C_Buffer[1]); i++; if(i > 16) i=0; #else uint16_t I2C_Buffer; I2C_Buffer = PCF8575_Pin_0 | PCF8575_Pin_8 | PCF8575_Pin_9; GPIO_ToggleBit(GPIOA, GPIO_Pin_3); I2C2_HalfWordWrite(PCF8575_ADDRESS, I2C_Buffer); I2C_Buffer = 0; DEBUGPRINT("R1 %X\r\n", I2C2_HalfWordRead(PCF8575_ADDRESS)); if(PCF8575_ReadInputDataBit(PCF8575_Pin_0) == Bit_SET){ DEBUGPRINT("P0 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_1) == Bit_SET){ DEBUGPRINT("P1 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_2) == Bit_SET){ DEBUGPRINT("P2 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_3) == Bit_SET){ DEBUGPRINT("P3 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_4) == Bit_SET){ DEBUGPRINT("P4 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_5) == Bit_SET){ DEBUGPRINT("P5 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_6) == Bit_SET){ DEBUGPRINT("P6 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_7) == Bit_SET){ DEBUGPRINT("P7 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_8) == Bit_SET){ DEBUGPRINT("P8 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_9) == Bit_SET){ DEBUGPRINT("P9 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_10) == Bit_SET){ DEBUGPRINT("P10 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_11) == Bit_SET){ DEBUGPRINT("P11 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_12) == Bit_SET){ DEBUGPRINT("P12 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_13) == Bit_SET){ DEBUGPRINT("P13 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_14) == Bit_SET){ DEBUGPRINT("P14 Set\r\n"); } if(PCF8575_ReadInputDataBit(PCF8575_Pin_15) == Bit_SET){ DEBUGPRINT("P15 Set\r\n"); } delay_ms(500); I2C_Buffer = 0; GPIO_ToggleBit(GPIOA, GPIO_Pin_3); I2C2_HalfWordWrite(PCF8575_ADDRESS, I2C_Buffer); I2C_Buffer = 0; // DEBUGPRINT("R2 %X\r\n", I2C2_HalfWordRead(PCF8575_ADDRESS)); delay_ms(500); #endif } } |
from: https://eroro.tistory.com/608 PWM 주파수 설정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
/* 40kHz */ Set_US_CTRLDuty(40000, 50); /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void TIM3_Init(u8 a_chOption, u32 a_nPrescaler, u32 a_nPeriod, u16 a_nDuty) { GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; if(a_chOption == 1){ /* TIM Disable */ TIM3->CR1 &= (uint16_t)~TIM_CR1_CEN; /* Init TIM Status */ TIM3->CNT = 0; TIM3->SR = 0; TIM3->CCR1 = 0; /* CH1 */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); if(a_nDuty == 0) GPIO_ResetBits(GPIOA, GPIO_Pin_6); else GPIO_SetBits(GPIOA, GPIO_Pin_6); /* GPIOA Configuration:TIM1 Channel 1 alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); } else{ /* TIM Disable */ TIM3->CR1 &= (uint16_t)~TIM_CR1_CEN; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); /* CH1 */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /* GPIOA Configuration:TIM1 Channel 1 alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Time base configuration */ /* TIM3 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; #if 0 /* 1us */ TIM_TimeBaseStructure.TIM_Prescaler = 72-1;//72Mhz #else TIM_TimeBaseStructure.TIM_Prescaler = a_nPrescaler-1; #endif TIM_TimeBaseStructure.TIM_Period = a_nPeriod - 1; //(72MHz/72)/a_nPeriod = x Hz TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); /* Init TIM Status */ TIM3->CNT = 0; TIM3->SR = 0; /* PWM1 Mode configuration: Channel 1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_Pulse = a_nDuty;//a_nDuty; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; #if 0 TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; #else TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; #endif TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OC1Init(TIM3, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); TIM_ARRPreloadConfig(TIM3, ENABLE); /* TIM3 enable counter */ TIM_Cmd(TIM3, ENABLE); TIM_CtrlPWMOutputs(TIM3, ENABLE); } } #define TIMPRESCLER_1 1 #define TIMPRESCLER_2 2 #define TIMPRESCLER_10 10 #define TIMPRESCLER_20 20 #define TIMPRESCLER_100 100 #define TIMPRESCLER_200 200 #define TIMPRESCLER_1000 1000 #define TIMPRESCLER_10000 10000 #define TIMPRESCLER_20000 20000 #define TIM3CLOCK 72000000 #define MAXDUTY 100 #define MAXFREQ 50000 #define MINFREQ 0 /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ void Set_US_CTRLDuty(u16 Frequency, u8 a_chLD_CTRLPWM) { __IO uint16_t Prescler = 0; __IO uint32_t Period = 0; __IO uint32_t Duty = 0; if(Frequency > MAXFREQ) Frequency = MAXFREQ; if(a_chLD_CTRLPWM >= MAXDUTY) a_chLD_CTRLPWM = MAXDUTY; #if defined(PRINTLD) DEBUGPRINT("Frequency %d\r\n", Frequency); DEBUGPRINT("Pulse %d\r\n", a_chLD_CTRLPWM); #endif if(Frequency > MINFREQ){ if(Frequency >= 1400){ Prescler = TIMPRESCLER_1; Period = (TIM3CLOCK/(TIMPRESCLER_1))/Frequency; Duty = (Period * a_chLD_CTRLPWM)/MAXDUTY; } else if(Frequency < 1400 && Frequency >= 140){ Prescler = TIMPRESCLER_10; Period = (TIM3CLOCK/(TIMPRESCLER_10))/Frequency; Duty = (Period * a_chLD_CTRLPWM)/MAXDUTY; } else if(Frequency < 140 && Frequency >= 14){ Prescler = TIMPRESCLER_100; Period = (TIM3CLOCK/(TIMPRESCLER_100))/Frequency; Duty = (Period * a_chLD_CTRLPWM)/MAXDUTY; } else{ Prescler = TIMPRESCLER_10000; Period = (TIM3CLOCK/(TIMPRESCLER_10000))/Frequency; Duty = (Period * a_chLD_CTRLPWM)/MAXDUTY; } /* TIM3 */ TIM3_Init(0, (u16)Prescler, Period, Duty); } else{ TIM3_Init(1, 0, 0, a_chLD_CTRLPWM); } #if 1 DEBUGPRINT("Prescler %d, Period %d, Duty %d\r\n", Prescler, Period, Duty); #endif } |
https://eroro.tistory.com/579 SPI를 GPIO로 처리한 부분을 추가하였습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
/* MIT License Copyright (c) 2016 D. Nesvera Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef NRF24L01_H #define NRF24L01_H #ifdef __cplusplus extern "C" { #endif #include "stm32f1xx_hal.h" #include "stm32f1xx_hal_spi.h" #define MAXPAYLOADSIZE 32 /** * @brief Transmission status enumeration */ typedef enum { NRF24L01_Transmit_Status_Lost = 0x00, /*!< Message is lost, reached maximum number of retransmissions */ NRF24L01_Transmit_Status_Ok = 0x01, /*!< Message sent successfully */ NRF24L01_Transmit_Status_Sending = 0xFF /*!< Message is still sending */ } NRF24L01_Transmit_Status_t; /** * @brief Data rate enumeration */ typedef enum { NRF24L01_DataRate_2M, /*!< Data rate set to 2Mbps */ NRF24L01_DataRate_1M, /*!< Data rate set to 1Mbps */ NRF24L01_DataRate_250k /*!< Data rate set to 250kbps */ } NRF24L01_DataRate_t; /** * @brief Output power enumeration */ typedef enum { NRF24L01_OutputPower_M18dBm, /*!< Output power set to -18dBm */ NRF24L01_OutputPower_M12dBm, /*!< Output power set to -12dBm */ NRF24L01_OutputPower_M6dBm, /*!< Output power set to -6dBm */ NRF24L01_OutputPower_0dBm /*!< Output power set to 0dBm */ } NRF24L01_OutputPower_t; /** * @brief CRC encoding scheme enumeration */ typedef enum{ NRF24L01_CRC_Disable = 0, NRF24L01_CRC_8, NRF24L01_CRC_16 } NRF24L01_CrcLength_t; typedef enum{ NRF24L01_TX_Mode = 0, NRF24L01_RX_Mode } NRF24L01_TRXMode_t; /** * @brief Struct of the NRF24L01 pins */ typedef struct { GPIO_TypeDef* GPIOx; uint16_t GPIO_Pin; } PIN_t; typedef struct { PIN_t CE; PIN_t CSN; PIN_t SCK; PIN_t MOSI; PIN_t MISO; PIN_t IRQ; } NRF24L01_Pins_t; /* Gets interrupt status from device */ #define NRF24L01_GET_INTERRUPTS TM_NRF24L01_GetStatus() /* Interrupt masks */ #define NRF24L01_IRQ_DATA_READY 0x40 /*!< Data ready for receive */ #define NRF24L01_IRQ_TRAN_OK 0x20 /*!< Transmission went OK */ #define NRF24L01_IRQ_MAX_RT 0x10 /*!< Max retransmissions reached, last transmission failed */ /** * @brief Assert the CE pin */ void NRF24L01_CE_LOW(void); /** * @brief Assert the CE pin */ void NRF24L01_CE_HIGH(void); /** * @brief De-assert the CSN pin */ void NRF24L01_CSN_LOW(void); /** * @brief Assert the CSN pin */ void NRF24L01_CSN_HIGH(void); /** * @brief Assert bits [6] [5] [4] to clear this bits of STATUS register */ void NRF24L01_ClearInterrupts(void); /** * @brief Flush TX FIFO, used in TX mode */ void NRF24L01_FlushTx(void); /** * @brief Flush RX FIFO, used in RX mode. * @note Should not be executed during transmission of acknowledge, that is, acknowledge package will not be completed. */ void NRF24L01_FlushRx(void); /** * @brief Initializes NRF24L01 module * @param channel: channel you will use for communication, from 0 to 125 eg. working frequency from 2.4 to 2.525 GHz * @param payload_size: maximum data to be sent in one packet from one NRF to another. * @note Maximal payload size is 32bytes * @param hspi: pointer to a SPI_HandleTypeDef structure that contains * the configuration information for SPI module. * @retval 1 */ uint8_t NRF24L01_Init(uint8_t channel, uint8_t payload_size, SPI_HandleTypeDef *hspi, NRF24L01_Pins_t pins, uint8_t mode ); /** * @brief Sets own address. This is used for settings own id when communication with other modules * @note "Own" address of one device must be the same as "TX" address of other device (and vice versa), * if you want to get successful communication * @param *adr: Pointer to 5-bytes length array with address * @retval None */ void NRF24L01_SetRxAddress(uint8_t* adr); /** * @brief Sets address you will communicate with * @note "Own" address of one device must be the same as "TX" address of other device (and vice versa), * if you want to get successful communication * @param *adr: Pointer to 5-bytes length array with address * @retval None */ void NRF24L01_SetTxAddress(uint8_t* adr); /** * @brief Gets number of retransmissions needed in last transmission * @param None * @retval Number of retransmissions, between 0 and 15. */ uint8_t NRF24L01_GetRetransmissionsCount(void); /** * @brief Sets NRF24L01+ to TX mode * @note In this mode is NRF able to send data to another NRF module * @param None * @retval None */ void NRF24L01_PowerUpTx(void); /** * @brief Sets NRF24L01+ to RX mode * @note In this mode is NRF able to receive data from another NRF module. * This is default mode and should be used all the time, except when sending data * @param None * @retval None */ void NRF24L01_PowerUpRx(void); /** * @brief Sets NRF24L01+ to power down mode * @note In power down mode, you are not able to transmit/receive data. * You can wake up device using @ref TM_NRF24L01_PowerUpTx() or @ref TM_NRF24L01_PowerUpRx() functions * All register values available are maintained and th SPI is kept active. * @param None * @retval None */ void NRF24L01_PowerDown(void); /** * @brief Leave low-power mode * @param None * @retval None */ void NRF24L01_PowerUP(void); /** * @brief Gets transmissions status * @param None * @retval Transmission status. Return is based on @ref TM_NRF24L01_Transmit_Status_t enumeration */ NRF24L01_Transmit_Status_t NRF24L01_GetTransmissionStatus(void); /** * @brief Transmits data with NRF24L01+ to another NRF module * @param *data: Pointer to 8-bit array with data. * Maximum length of array can be the same as "payload_size" parameter on initialization * @retval This parameter can be a value of @ref NRF24L01_Transmit_Status_t enumeration */ NRF24L01_Transmit_Status_t NRF24L01_Transmit(const void *data); /** * @brief Checks if data is ready to be read from NRF24L01+ * @param None * @retval Data ready status: * - 0: No data available for receive in bufferReturns * - > 0: Data is ready to be collected */ uint8_t NRF24L01_DataReady(void); /** * @brief Gets data from NRF24L01+ * @param *data: Pointer to 8-bits array where data from NRF will be saved * @retval None */ void NRF24L01_GetData(uint8_t *data); /** * @brief Sets working channel * @note Channel value is just an offset in units MHz from 2.4GHz * For example, if you select channel 65, then operation frequency will be set to 2.465GHz. * The channel occupies a bandwidth of less than 1MHz at 250kbps and 1Mbps and a bandwidth * of less than 2MHz at 2Mbps. * @param channel: RF channel where device will operate between 0 and 125 * @retval None */ void NRF24L01_SetChannel(uint8_t channel); /** * @brief Sets RF parameters for NRF24L01+ * @param DataRate: Data rate selection for NRF module. This parameter can be a value of @ref TM_NRF24L01_DataRate_t enumeration * @param OutPwr: Output power selection for NRF module. This parameter can be a value of @ref TM_NRF24L01_OutputPower_t enumeration * @retval None */ void NRF24L01_SetRF( NRF24L01_DataRate_t DataRate, NRF24L01_OutputPower_t OutPwr); /** * @brief Sets Power Amplifier(PA) level to one of four levels. * @param OutPwr: Output power selection for NRF module. This parameter can be a value of @ref TM_NRF24L01_OutputPower_t enumeration * @retval None */ void NRF24L01_SetPaLevel( NRF24L01_OutputPower_t OutPwr ); /** * @brief Gets the current Power Amplifier(PA) level. * @retval Returns a value from the NRF24L01_OutputPower_t enum describing the current PA setting. */ NRF24L01_OutputPower_t NRF24L01_GetPaLevel( void ); /** * @brief Set the transmission data rate * @param DataRate: Data rate selection for NRF module. This parameter can be a value of @ref TM_NRF24L01_DataRate_t enumeration */ void NRF24L01_SetDataRate( NRF24L01_DataRate_t DataRate ); /** * @brief Gets the current transmission data rate. * @retval Returns a value from the NRF24L01_DataRate_t enum describing the current data rate. */ NRF24L01_DataRate_t NRF24L01_GetDataRate( void ); /** * @brief Gets NRLF+ status register value * @param None * @retval Status register from NRF */ uint8_t NRF24L01_GetStatus(void); /** * @brief Gets NRLF+ status register value * @param Length: length for 8bits, 16bits or disable CRC * @retval None */ void NRF24L01_SetCrcLength( NRF24L01_CrcLength_t length ); // void NRF24L01_getCrcLength( NRF24L01_CrcLength_t length ); /** * @brief Test whether there are bytes available to be read * @note Use this version to discover on which pipe the message arrived. * @retval true(0x01) if there is a payload available, false(0x00) if there is no payload */ uint8_t NRF24L01_Available( void ); /** * @brief Enable or disable auto-acknowledgment function * @note This is enabled by default, so it's only needed if you want to turn it off for some reason. * @param pipe: which pipeline you want to modify - 0xFF disable all pipes * @param State: 0x00 = disable 0x01 = enable * @retval None */ void NRF24L01_SetAutoAck( uint8_t pipe, uint8_t state ); /** * @brief Test whether there was a carrier on the line for the previous listening period * @note Useful to check for interference on the current channel. * @retval true(0x01) if received power levels above -64dBm, false(0x00) if received power is less than -64dBm. */ uint8_t NRF24L01_TestCarrier(void); /** * @brief Open a pipe for writing - transmission * @note Only one pipe can be open at once, but you can change the pipe you will listen to. Do not call * call this this while actively listening, call stopListening() fist. * @param Address: * @retval None */ void NRF24L01_OpenWritingPipe( uint8_t* address ); /** * @brief Open a pipe for reading - receive * @note Up to 6 pipes can be open for reading at once. Open all the * reading pipes, and then call startListening(). * @param Number: which pipe to open, 0-5 * @param Address: the 40bits address of the pipe to open * @retval None */ void NRF24L01_OpenReadingPipe( uint8_t number, uint8_t* address ); /** * @brief Start listening on the pipes opened for reading. - Go to Rx mode * @note Be sure to call openReadingPipe() first. Do not call write() while * in this mode, without first calling stopListening(). Call * isAvailable() to check for incoming traffic, and read() to get it. * @retval None */ void NRF24L01_StartListening(void); /** * @brief Stop listening for incoming messages - return to standby-I * @note Do this before calling write(). * @retval None */ void NRF24L01_StopListening(void); /** * @brief Read the payload * @note Return the last payload received * @param Data: pointer to a buffer where the data should be written * @retval None */ uint8_t NRF24L01_Read(void* data); /** * @brief Get Static payload size * @retval Number of bytes in the payload */ uint8_t NRF24L01_GetPayloadSize(void); /** * @brief Get Dynamic payload size * @retval Payload size of last received dynamic payload */ uint8_t NRF24L01_GetDynamicPayloadSize(void); /** * @brief Set the number and delay of retries upon failed submit * @param delay How long to wait between each retry, in multiples of 250us, * max is 15. 0 means 250us, 15 means 4000us. * @param count How many retries before giving up, max 15 * @retval NONE */ void NRF24L01_SetRetries(uint8_t delay, uint8_t count); #endif /* __NRF24L01_H */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 |
/* MIT License Copyright (c) 2016 D. Nesvera Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "main.h" #include "nrf24l01c.h" #include "stm32f1xx_hal.h" // APAGAR BUG REVER #define _SSPI_ 1 uint8_t SPI_SendByte(uint8_t byte); // colocar os copyright // os dataseet do nrf link // os datasheet do stm link // based /* NRF24L01+ registers*/ #define NRF24L01_REG_CONFIG 0x00 //Configuration Register #define NRF24L01_REG_EN_AA 0x01 //Enable ‘Auto Acknowledgment’ Function #define NRF24L01_REG_EN_RXADDR 0x02 //Enabled RX Addresses #define NRF24L01_REG_SETUP_AW 0x03 //Setup of Address Widths (common for all data pipes) #define NRF24L01_REG_SETUP_RETR 0x04 //Setup of Automatic Retransmission #define NRF24L01_REG_RF_CH 0x05 //RF Channel #define NRF24L01_REG_RF_SETUP 0x06 //RF Setup Register #define NRF24L01_REG_STATUS 0x07 //Status Register #define NRF24L01_REG_OBSERVE_TX 0x08 //Transmit observe register #define NRF24L01_REG_RPD 0x09 #define NRF24L01_REG_RX_ADDR_P0 0x0A //Receive address data pipe 0. 5 Bytes maximum length. #define NRF24L01_REG_RX_ADDR_P1 0x0B //Receive address data pipe 1. 5 Bytes maximum length. #define NRF24L01_REG_RX_ADDR_P2 0x0C //Receive address data pipe 2. Only LSB #define NRF24L01_REG_RX_ADDR_P3 0x0D //Receive address data pipe 3. Only LSB #define NRF24L01_REG_RX_ADDR_P4 0x0E //Receive address data pipe 4. Only LSB #define NRF24L01_REG_RX_ADDR_P5 0x0F //Receive address data pipe 5. Only LSB #define NRF24L01_REG_TX_ADDR 0x10 //Transmit address. Used for a PTX device only #define NRF24L01_REG_RX_PW_P0 0x11 #define NRF24L01_REG_RX_PW_P1 0x12 #define NRF24L01_REG_RX_PW_P2 0x13 #define NRF24L01_REG_RX_PW_P3 0x14 #define NRF24L01_REG_RX_PW_P4 0x15 #define NRF24L01_REG_RX_PW_P5 0x16 #define NRF24L01_REG_FIFO_STATUS 0x17 //FIFO Status Register #define NRF24L01_REG_DYNPD 0x1C //Enable dynamic payload length #define NRF24L01_REG_FEATURE 0x1D /* Registers default values */ #define NRF24L01_REG_DEFAULT_VAL_CONFIG 0x08 #define NRF24L01_REG_DEFAULT_VAL_EN_AA 0x3F #define NRF24L01_REG_DEFAULT_VAL_EN_RXADDR 0x03 #define NRF24L01_REG_DEFAULT_VAL_SETUP_AW 0x03 #define NRF24L01_REG_DEFAULT_VAL_SETUP_RETR 0x03 #define NRF24L01_REG_DEFAULT_VAL_RF_CH 0x02 #define NRF24L01_REG_DEFAULT_VAL_RF_SETUP 0x0E #define NRF24L01_REG_DEFAULT_VAL_STATUS 0x0E #define NRF24L01_REG_DEFAULT_VAL_OBSERVE_TX 0x00 #define NRF24L01_REG_DEFAULT_VAL_RPD 0x00 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P0_0 0xE7 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P0_1 0xE7 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P0_2 0xE7 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P0_3 0xE7 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P0_4 0xE7 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P1_0 0xC2 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P1_1 0xC2 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P1_2 0xC2 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P1_3 0xC2 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P1_4 0xC2 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P2 0xC3 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P3 0xC4 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P4 0xC5 #define NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P5 0xC6 #define NRF24L01_REG_DEFAULT_VAL_TX_ADDR_0 0xE7 #define NRF24L01_REG_DEFAULT_VAL_TX_ADDR_1 0xE7 #define NRF24L01_REG_DEFAULT_VAL_TX_ADDR_2 0xE7 #define NRF24L01_REG_DEFAULT_VAL_TX_ADDR_3 0xE7 #define NRF24L01_REG_DEFAULT_VAL_TX_ADDR_4 0xE7 #define NRF24L01_REG_DEFAULT_VAL_RX_PW_P0 0x00 #define NRF24L01_REG_DEFAULT_VAL_RX_PW_P1 0x00 #define NRF24L01_REG_DEFAULT_VAL_RX_PW_P2 0x00 #define NRF24L01_REG_DEFAULT_VAL_RX_PW_P3 0x00 #define NRF24L01_REG_DEFAULT_VAL_RX_PW_P4 0x00 #define NRF24L01_REG_DEFAULT_VAL_RX_PW_P5 0x00 #define NRF24L01_REG_DEFAULT_VAL_FIFO_STATUS 0x17 //0x11 do codigo original #define NRF24L01_REG_DEFAULT_VAL_DYNPD 0x00 #define NRF24L01_REG_DEFAULT_VAL_FEATURE 0x00 /* Commands */ #define NRF24L01_CMD_R_REGISTER 0x00 #define NRF24L01_CMD_W_REGISTER 0x20 #define NRF24L01_CMD_R_RX_PAYLOAD 0x61 #define NRF24L01_CMD_W_TX_PAYLOAD 0xA0 #define NRF24L01_CMD_FLUSH_TX 0xE1 #define NRF24L01_CMD_FLUSH_RX 0xE2 #define NRF24L01_CMD_REUSE_TX_PL 0xE3 #define NRF24L01_CMD_ACTIVATE 0x50 #define NRF24L01_CMD_R_RX_PL_WID 0x60 #define NRF24L01_CMD_W_ACK_PAYLOAD 0xA8 #define NRF24L01_CMD_W_TX_PAYLOAD_NOACK 0xB0 #define NRF24L01_CMD_NOP 0xFF #define NRF24L01_SPI_TIMEOUT 2000 #define NRF24L01_TX_TIMEOUT 500 #define NRF24L01_RX_TIMEOUT 500 /* Configuration register*/ #define NRF24L01_MASK_RX_DR 6 #define NRF24L01_MASK_TX_DS 5 #define NRF24L01_MASK_MAX_RT 4 #define NRF24L01_EN_CRC 3 #define NRF24L01_CRCO 2 #define NRF24L01_PWR_UP 1 #define NRF24L01_PRIM_RX 0 /* RX/TX control */ #define PRX 1 // primary receiver mode #define PTX 0 // primary transmitter mode /* Enable auto acknowledgment*/ #define NRF24L01_ENAA_P5 5 #define NRF24L01_ENAA_P4 4 #define NRF24L01_ENAA_P3 3 #define NRF24L01_ENAA_P2 2 #define NRF24L01_ENAA_P1 1 #define NRF24L01_ENAA_P0 0 /* Enable rx addresses */ #define NRF24L01_ERX_P5 5 #define NRF24L01_ERX_P4 4 #define NRF24L01_ERX_P3 3 #define NRF24L01_ERX_P2 2 #define NRF24L01_ERX_P1 1 #define NRF24L01_ERX_P0 0 /* Setup of address width */ #define NRF24L01_AW 0 //2 bits /* Setup of auto re-transmission*/ #define NRF24L01_ARD 4 //4 bits #define NRF24L01_ARC 0 //4 bits /* RF setup register*/ #define NRF24L01_PLL_LOCK 4 #define NRF24L01_RF_DR_LOW 5 #define NRF24L01_RF_DR_HIGH 3 #define NRF24L01_RF_DR 3 #define NRF24L01_RF_PWR 1 //2 bits /* General status register */ #define NRF24L01_RX_DR 6 #define NRF24L01_TX_DS 5 #define NRF24L01_MAX_RT 4 #define NRF24L01_RX_P_NO 1 //3 bits #define NRF24L01_TX_FULL 0 /* Transmit observe register */ #define NRF24L01_PLOS_CNT 4 //4 bits #define NRF24L01_ARC_CNT 0 //4 bits /* FIFO status*/ #define NRF24L01_TX_REUSE 6 #define NRF24L01_FIFO_FULL 5 #define NRF24L01_TX_EMPTY 4 #define NRF24L01_RX_FULL 1 #define NRF24L01_RX_EMPTY 0 //Dynamic length #define NRF24L01_DPL_P0 0 #define NRF24L01_DPL_P1 1 #define NRF24L01_DPL_P2 2 #define NRF24L01_DPL_P3 3 #define NRF24L01_DPL_P4 4 #define NRF24L01_DPL_P5 5 /* Transmitter power*/ #define NRF24L01_M18DBM 0 //-18 dBm #define NRF24L01_M12DBM 1 //-12 dBm #define NRF24L01_M6DBM 2 //-6 dBm #define NRF24L01_0DBM 3 //0 dBm /* Data rates */ #define NRF24L01_2MBPS 0 #define NRF24L01_1MBPS 1 #define NRF24L01_250KBPS 2 /* Configuration */ #define NRF24L01_CONFIG ((1 << NRF24L01_EN_CRC) | (0 << NRF24L01_CRCO)) #define NRF24L01_TRANSMISSON_OK 0 #define NRF24L01_MESSAGE_LOST 1 #define NRF24L01_CHECK_BIT(value, bit) (value & (1 << bit)) typedef struct { uint8_t PayloadSize; //Payload size uint8_t Channel; //Channel selected NRF24L01_OutputPower_t OutPwr; //Output power NRF24L01_DataRate_t DataRate; //Data rate SPI_HandleTypeDef *hspi; //hspi: pointer to a SPI_HandleTypeDef structure that contains the configuration information for SPI module. } NRF24L01_t; /* Private functions */ void NRF24L01_InitPins(void); uint8_t NRF24L01_ReadBit(uint8_t reg, uint8_t bit); uint8_t NRF24L01_ReadRegister(uint8_t reg); void NRF24L01_ReadRegisterMulti(uint8_t reg, uint8_t* data, uint8_t length); uint8_t NRF24L01_RxFifoEmpty(void); void NRF24L01_SoftwareReset(void); void NRF24L01_WriteBit(uint8_t reg, uint8_t bit, uint8_t value); void NRF24L01_WriteRegister( uint8_t reg, uint8_t value ); void NRF24L01_WriteRegisterMulti(uint8_t reg, uint8_t *data, uint8_t length); void NRF24L01_SpiInit( SPI_HandleTypeDef *hspi, NRF24L01_Pins_t pins ); /* NRF structure */ static NRF24L01_t NRF24L01_Struct; /* NRF Pins structure */ static NRF24L01_Pins_t NRF24L01_Pins; uint8_t pipe0_reading_address[5]; // last address set on pipe 0 for reading void NRF24L01_CE_LOW() { HAL_GPIO_WritePin( NRF24L01_Pins.CE.GPIOx, NRF24L01_Pins.CE.GPIO_Pin, GPIO_PIN_RESET ); } void NRF24L01_CE_HIGH(void) { HAL_GPIO_WritePin( NRF24L01_Pins.CE.GPIOx, NRF24L01_Pins.CE.GPIO_Pin, GPIO_PIN_SET ); } void NRF24L01_CSN_LOW(void) { HAL_GPIO_WritePin( NRF24L01_Pins.CSN.GPIOx, NRF24L01_Pins.CSN.GPIO_Pin, GPIO_PIN_RESET ); } void NRF24L01_CSN_HIGH(void) { HAL_GPIO_WritePin( NRF24L01_Pins.CSN.GPIOx, NRF24L01_Pins.CSN.GPIO_Pin, GPIO_PIN_SET ); } /* Clear interrupt flags */ void NRF24L01_ClearInterrupts(void) { NRF24L01_WriteRegister( NRF24L01_REG_STATUS, (1<<NRF24L01_RX_DR)|(1<<NRF24L01_TX_DS)|(1<<NRF24L01_MAX_RT) ); // setting bits 4,5,6 } /* Flush FIFOs */ void NRF24L01_FlushRx(void) { NRF24L01_CSN_LOW(); uint8_t aux = NRF24L01_CMD_FLUSH_RX; #ifdef _SSPI_ SPI_SendByte(aux); #else HAL_SPI_Transmit( NRF24L01_Struct.hspi, &aux, 1, NRF24L01_SPI_TIMEOUT ); #endif NRF24L01_CSN_HIGH(); } void NRF24L01_FlushTx(void) { NRF24L01_CSN_LOW(); uint8_t aux = NRF24L01_CMD_FLUSH_TX; #ifdef _SSPI_ SPI_SendByte(aux); #else HAL_SPI_Transmit( NRF24L01_Struct.hspi, &aux, 1, NRF24L01_SPI_TIMEOUT ); #endif NRF24L01_CSN_HIGH(); } void TM_NRF24L01_Dump_Reg(void) { uint8_t addr[5]; int i; printf("\r\nnRF14L01 Registers Value\r\n"); printf(" CONFIG : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_CONFIG)); printf(" EN_AA : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_EN_AA)); printf(" EN_RXADDR : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_EN_RXADDR)); printf(" SETUP_AW : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_SETUP_AW)); printf("SETUP_RETR : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_SETUP_RETR)); printf(" RF_CH : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RF_CH)); printf(" RF_SETUP : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RF_SETUP)); printf(" STATUS : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_STATUS)); printf("OBSERVE_TX : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_OBSERVE_TX)); printf(" RPD : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RPD)); NRF24L01_ReadRegisterMulti(NRF24L01_REG_RX_ADDR_P0, addr, 5); printf("RX_ADDR_P0 : "); for (i=0; i<5; i++) printf("%02X", addr[i]); printf("\r\n"); NRF24L01_ReadRegisterMulti(NRF24L01_REG_RX_ADDR_P1, addr, 5); printf("RX_ADDR_P1 : "); for (i=0; i<5; i++) printf("%02X", addr[i]); printf("\r\n"); printf("RX_ADDR_P2 : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RX_ADDR_P2)); printf("RX_ADDR_P3 : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RX_ADDR_P3)); printf("RX_ADDR_P4 : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RX_ADDR_P4)); printf("RX_ADDR_P5 : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RX_ADDR_P5)); NRF24L01_ReadRegisterMulti(NRF24L01_REG_TX_ADDR, addr, 5); printf(" TX_ADDR : "); for (i=0; i<5; i++) printf("%02X", addr[i]); printf("\r\n"); printf(" RX_PWD_P0 : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RX_PW_P0)); printf(" RX_PWD_P1 : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RX_PW_P1)); printf(" RX_PWD_P2 : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RX_PW_P2)); printf(" RX_PWD_P3 : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RX_PW_P3)); printf(" RX_PWD_P4 : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RX_PW_P4)); printf(" RX_PWD_P5 : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_RX_PW_P5)); printf("FIFO_STATUS: %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_FIFO_STATUS)); printf(" DYNPD : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_DYNPD)); printf(" FEATURE : %02X\r\n", NRF24L01_ReadRegister(NRF24L01_REG_FEATURE)); } void nrf24l01p_prx_mode() { uint8_t new_config = NRF24L01_ReadRegister(NRF24L01_REG_CONFIG); new_config |= 1 << 0; NRF24L01_WriteRegister(NRF24L01_REG_CONFIG, new_config); } void nrf24l01p_ptx_mode() { uint8_t new_config = NRF24L01_ReadRegister(NRF24L01_REG_CONFIG); new_config &= 0xFE; NRF24L01_WriteRegister(NRF24L01_REG_CONFIG, new_config); } uint8_t NRF24L01_Init(uint8_t channel, uint8_t payload_size, SPI_HandleTypeDef *hspi, NRF24L01_Pins_t pins, uint8_t mode ) { NRF24L01_Pins = pins; for( int ind = 0 ; ind < 5 ; ind++ ) pipe0_reading_address[ind] = 0; // Initialize SPI NRF24L01_SpiInit( hspi, NRF24L01_Pins ); // We can consider the worst settle time and use to all HAL_Delay(5); /* Max payload is 32bytes */ if (payload_size > MAXPAYLOADSIZE){ payload_size = MAXPAYLOADSIZE; } /* Fill structure */ NRF24L01_Struct.Channel = !channel; /* Set channel to some different value for TM_NRF24L01_SetChannel() function */ NRF24L01_Struct.PayloadSize = payload_size; NRF24L01_Struct.OutPwr = NRF24L01_OutputPower_0dBm; NRF24L01_Struct.DataRate = NRF24L01_DataRate_250k; NRF24L01_Struct.hspi = hspi; /* Reset nRF24L01+ to power on registers values */ NRF24L01_SoftwareReset(); // if(mode == NRF24L01_TX_Mode) // nrf24l01p_ptx_mode(); // else if(mode == NRF24L01_RX_Mode) // nrf24l01p_prx_mode(); // else // ; TM_NRF24L01_Dump_Reg(); /* Set 1500uS timeouts ( minimum for 32 bytes payload in 250KBPS ) */ NRF24L01_WriteRegister( NRF24L01_REG_SETUP_RETR, ((4 << NRF24L01_ARD)|(15 << NRF24L01_ARC)) ); /* Channel select */ NRF24L01_SetChannel(channel); /* Set pipeline to the payload size */ NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P0, NRF24L01_Struct.PayloadSize); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P1, NRF24L01_Struct.PayloadSize); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P2, NRF24L01_Struct.PayloadSize); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P3, NRF24L01_Struct.PayloadSize); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P4, NRF24L01_Struct.PayloadSize); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P5, NRF24L01_Struct.PayloadSize); /* Set RF settings (1mbps, output power) */ NRF24L01_SetRF( NRF24L01_Struct.DataRate, NRF24L01_Struct.OutPwr); /* Config register */ NRF24L01_WriteRegister(NRF24L01_REG_CONFIG, NRF24L01_CONFIG); /* Enable auto-acknowledgment for all pipes */ NRF24L01_WriteRegister(NRF24L01_REG_EN_AA, 0x3F); /* Enable RX addresses */ NRF24L01_WriteRegister(NRF24L01_REG_EN_RXADDR, 0x3F); /* Auto retransmit delay: 1000 (4x250) us and Up to 15 retransmit trials */ NRF24L01_WriteRegister(NRF24L01_REG_SETUP_RETR, 0x4F); /* Dynamic length configurations: No dynamic length */ NRF24L01_WriteRegister(NRF24L01_REG_DYNPD, (0 << NRF24L01_DPL_P0) | (0 << NRF24L01_DPL_P1) | (0 << NRF24L01_DPL_P2) | (0 << NRF24L01_DPL_P3) | (0 << NRF24L01_DPL_P4) | (0 << NRF24L01_DPL_P5)); /* Initialize CRC 2bytes */ NRF24L01_SetCrcLength( NRF24L01_CRC_16 ); /* Clear FIFOs */ NRF24L01_FlushTx(); NRF24L01_FlushRx(); /* Clear interrupts */ NRF24L01_ClearInterrupts(); /* Go to RX mode */ NRF24L01_PowerUpRx(); /* Return OK */ return 1; } /******************************************************************************* * Function Name : void nRF24L01_DELAY(uint32_t nCount) * Description : Microsecond delay * Parameters : Microsecond conunt * Return : None *******************************************************************************/ void nRF24L01_DELAY(uint32_t nCount) { #if 1 nCount *= 1; for(; nCount!=0; nCount--){ __ASM volatile ("nop"); } #else __ASM volatile ("nop"); #endif } /******************************************************************************* * Function Name : * Parameters : * Return : none * Description : CSN(SS) high = disable SPI *******************************************************************************/ void nRF24L01CS_EN(FunctionalState NewState) { if (NewState == DISABLE){ HAL_GPIO_WritePin( SPIx_CSN_GPIO_PORT, SPIx_CSN_PIN, GPIO_PIN_RESET ); } else{ HAL_GPIO_WritePin( SPIx_CSN_GPIO_PORT, SPIx_CSN_PIN, GPIO_PIN_SET ); } } /******************************************************************************* * Function Name : * Parameters : * Return : none * Description : RF EN CE low = disable TX/RX *******************************************************************************/ void nRF24L01CE_EN(FunctionalState NewState) { if (NewState == DISABLE){ HAL_GPIO_WritePin( SPIx_CE_GPIO_PORT, SPIx_CE_PIN, GPIO_PIN_RESET ); } else{ HAL_GPIO_WritePin( SPIx_CE_GPIO_PORT, SPIx_CE_PIN, GPIO_PIN_SET ); } } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void SPI_CS_HIGH(void) { HAL_GPIO_WritePin( SPIx_CSN_GPIO_PORT, SPIx_CSN_PIN, GPIO_PIN_SET ); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void SPI_CS_LOW(void) { HAL_GPIO_WritePin( SPIx_CSN_GPIO_PORT, SPIx_CSN_PIN, GPIO_PIN_RESET ); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ uint8_t SPI_SendByte(uint8_t byte) { uint8_t RXDat = 0; uint8_t SPI_count; for (SPI_count = 0; SPI_count < 8; SPI_count++){ if((byte & 0x80) == 0x80){ HAL_GPIO_WritePin( SPIx_MOSI_GPIO_PORT, SPIx_MOSI_PIN, GPIO_PIN_SET );//MOSI HIGH } else{ HAL_GPIO_WritePin( SPIx_MOSI_GPIO_PORT, SPIx_MOSI_PIN, GPIO_PIN_RESET );//MOSI LOW } byte = byte << 1; // shift next bit into MSB nRF24L01_DELAY(2); HAL_GPIO_WritePin( SPIx_SCK_GPIO_PORT, SPIx_SCK_PIN, GPIO_PIN_SET );//SCK HIGH nRF24L01_DELAY(3); RXDat = RXDat << 1; if(HAL_GPIO_ReadPin(SPIx_MISO_GPIO_PORT, SPIx_MISO_PIN) == GPIO_PIN_SET){ RXDat |= 0x01; } HAL_GPIO_WritePin( SPIx_SCK_GPIO_PORT, SPIx_SCK_PIN, GPIO_PIN_RESET );//SCK LOW nRF24L01_DELAY(2); } // RXDat = RXDat >> 1; /* Read SPIz received data */ return RXDat; } #define DUMMY_BYTE 0xA5 void SPI_BufferRead(uint8_t* pTXBuffer, uint8_t* pRXBuffer, uint16_t NumByteToRead) { while (NumByteToRead--) /* while there is data to be read */ { /* Read a byte from the FLASH */ *pRXBuffer = SPI_SendByte(*pTXBuffer); /* Point to the next location where the byte read will be saved */ pTXBuffer++; pRXBuffer++; } } void NRF24L01_SpiInit( SPI_HandleTypeDef *hspi, NRF24L01_Pins_t pins ) { #ifdef _SSPI_ GPIO_InitTypeDef GPIO_InitStruct; SPIx_SCK_GPIO_CLK_ENABLE(); SPIx_MISO_GPIO_CLK_ENABLE(); SPIx_MOSI_GPIO_CLK_ENABLE(); SPIx_CSN_GPIO_CLK_ENABLE(); SPIx_CE_GPIO_CLK_ENABLE(); /* LCD CS */ SPI_CS_HIGH(); /* SPI SCK GPIO pin configuration */ GPIO_InitStruct.Pin = SPIx_SCK_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStruct); /* SPI MOSI GPIO pin configuration */ GPIO_InitStruct.Pin = SPIx_MOSI_PIN; HAL_GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStruct); /* SPI MISO GPIO pin configuration */ GPIO_InitStruct.Pin = SPIx_MISO_PIN; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStruct); /* SPI CSN */ GPIO_InitStruct.Pin = SPIx_CSN_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(SPIx_CSN_GPIO_PORT, &GPIO_InitStruct); /* SPI CE */ GPIO_InitStruct.Pin = SPIx_CE_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(SPIx_CE_GPIO_PORT, &GPIO_InitStruct); #else GPIO_InitTypeDef GPIO_InitStruct; SPIx_SCK_GPIO_CLK_ENABLE(); SPIx_MISO_GPIO_CLK_ENABLE(); SPIx_MOSI_GPIO_CLK_ENABLE(); SPIx_CSN_GPIO_CLK_ENABLE(); SPIx_CE_GPIO_CLK_ENABLE(); /*##-1- Configure the SPI peripheral #######################################*/ hspi->Instance = SPIx;//SPI1; hspi->Init.Mode = SPI_MODE_MASTER; hspi->Init.Direction = SPI_DIRECTION_2LINES; hspi->Init.DataSize = SPI_DATASIZE_8BIT; hspi->Init.CLKPolarity = SPI_POLARITY_LOW; hspi->Init.CLKPhase = SPI_PHASE_1EDGE; hspi->Init.NSS = SPI_NSS_SOFT;//SPI_NSS_HARD_OUTPUT; hspi->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256; hspi->Init.FirstBit = SPI_FIRSTBIT_MSB; hspi->Init.TIMode = SPI_TIMODE_DISABLE; hspi->Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi->Init.CRCPolynomial = 10; HAL_SPI_Init(hspi); /**SPI1 GPIO Configuration PA4 ------> SPI1_NSS PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI ` */ /*##-2- Configure peripheral GPIO ##########################################*/ /* SPI SCK GPIO pin configuration */ GPIO_InitStruct.Pin = SPIx_SCK_PIN; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL;//GPIO_PULLDOWN; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(SPIx_SCK_GPIO_PORT, &GPIO_InitStruct); /* SPI MISO GPIO pin configuration */ GPIO_InitStruct.Pin = SPIx_MISO_PIN; HAL_GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStruct); /* SPI MOSI GPIO pin configuration */ GPIO_InitStruct.Pin = SPIx_MOSI_PIN; HAL_GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStruct); GPIO_InitStruct.Pin = SPIx_CSN_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(SPIx_CSN_GPIO_PORT, &GPIO_InitStruct); GPIO_InitStruct.Pin = SPIx_CE_PIN; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(SPIx_CE_GPIO_PORT, &GPIO_InitStruct); #endif /* CSN(SS) high = disable SPI */ HAL_GPIO_WritePin( SPIx_CSN_GPIO_PORT, SPIx_CSN_PIN, GPIO_PIN_SET ); /* CE low = disable TX/RX */ HAL_GPIO_WritePin( SPIx_CE_GPIO_PORT, SPIx_CE_PIN, GPIO_PIN_RESET ); } void NRF24L01_SoftwareReset(void) { uint8_t data[5]; NRF24L01_WriteRegister( NRF24L01_REG_CONFIG, NRF24L01_REG_DEFAULT_VAL_CONFIG); NRF24L01_WriteRegister( NRF24L01_REG_EN_AA, NRF24L01_REG_DEFAULT_VAL_EN_AA); NRF24L01_WriteRegister( NRF24L01_REG_EN_RXADDR, NRF24L01_REG_DEFAULT_VAL_EN_RXADDR); NRF24L01_WriteRegister( NRF24L01_REG_SETUP_AW, NRF24L01_REG_DEFAULT_VAL_SETUP_AW); NRF24L01_WriteRegister( NRF24L01_REG_SETUP_RETR, NRF24L01_REG_DEFAULT_VAL_SETUP_RETR); NRF24L01_WriteRegister( NRF24L01_REG_RF_CH, NRF24L01_REG_DEFAULT_VAL_RF_CH); NRF24L01_WriteRegister( NRF24L01_REG_RF_SETUP, NRF24L01_REG_DEFAULT_VAL_RF_SETUP); NRF24L01_WriteRegister( NRF24L01_REG_STATUS, NRF24L01_REG_DEFAULT_VAL_STATUS); NRF24L01_WriteRegister( NRF24L01_REG_OBSERVE_TX, NRF24L01_REG_DEFAULT_VAL_OBSERVE_TX); NRF24L01_WriteRegister( NRF24L01_REG_RPD, NRF24L01_REG_DEFAULT_VAL_RPD); //P0 data[0] = NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P0_0; data[1] = NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P0_1; data[2] = NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P0_2; data[3] = NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P0_3; data[4] = NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P0_4; NRF24L01_WriteRegisterMulti(NRF24L01_REG_RX_ADDR_P0, data, 5); //P1 data[0] = NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P1_0; data[1] = NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P1_1; data[2] = NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P1_2; data[3] = NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P1_3; data[4] = NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P1_4; NRF24L01_WriteRegisterMulti(NRF24L01_REG_RX_ADDR_P1, data, 5); NRF24L01_WriteRegister(NRF24L01_REG_RX_ADDR_P2, NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P2); NRF24L01_WriteRegister(NRF24L01_REG_RX_ADDR_P3, NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P3); NRF24L01_WriteRegister(NRF24L01_REG_RX_ADDR_P4, NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P4); NRF24L01_WriteRegister(NRF24L01_REG_RX_ADDR_P5, NRF24L01_REG_DEFAULT_VAL_RX_ADDR_P5); //TX data[0] = NRF24L01_REG_DEFAULT_VAL_TX_ADDR_0; data[1] = NRF24L01_REG_DEFAULT_VAL_TX_ADDR_1; data[2] = NRF24L01_REG_DEFAULT_VAL_TX_ADDR_2; data[3] = NRF24L01_REG_DEFAULT_VAL_TX_ADDR_3; data[4] = NRF24L01_REG_DEFAULT_VAL_TX_ADDR_4; NRF24L01_WriteRegisterMulti(NRF24L01_REG_TX_ADDR, data, 5); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P0, NRF24L01_REG_DEFAULT_VAL_RX_PW_P0); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P1, NRF24L01_REG_DEFAULT_VAL_RX_PW_P1); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P2, NRF24L01_REG_DEFAULT_VAL_RX_PW_P2); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P3, NRF24L01_REG_DEFAULT_VAL_RX_PW_P3); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P4, NRF24L01_REG_DEFAULT_VAL_RX_PW_P4); NRF24L01_WriteRegister(NRF24L01_REG_RX_PW_P5, NRF24L01_REG_DEFAULT_VAL_RX_PW_P5); NRF24L01_WriteRegister(NRF24L01_REG_FIFO_STATUS, NRF24L01_REG_DEFAULT_VAL_FIFO_STATUS); NRF24L01_WriteRegister(NRF24L01_REG_DYNPD, NRF24L01_REG_DEFAULT_VAL_DYNPD); NRF24L01_WriteRegister(NRF24L01_REG_FEATURE, NRF24L01_REG_DEFAULT_VAL_FEATURE); } /** * @brief Read a bit of the current register value * @param reg * @param bit * @param value */ uint8_t NRF24L01_ReadBit(uint8_t reg, uint8_t bit) { uint8_t tmp; tmp = NRF24L01_ReadRegister(reg); if (!NRF24L01_CHECK_BIT(tmp, bit)){ return 0; } return 1; } /** * @brief Change a bit of the current register value * @param reg * @param bit * @param value */ void NRF24L01_WriteBit(uint8_t reg, uint8_t bit, uint8_t value) { uint8_t tmp; /* Read register */ tmp = NRF24L01_ReadRegister(reg); /* Make operation */ if (value){ tmp |= 1 << bit; }else{ tmp &= ~(1 << bit); } /* Write back */ NRF24L01_WriteRegister(reg, tmp); } uint8_t NRF24L01_ReadRegister(uint8_t reg) { /* NRF24L01 shifts the value of status register at the first MOSI byte and at the second byte the value of the interested register */ // Initialize buffers uint8_t txBuffer[2]; txBuffer[0] = NRF24L01_CMD_R_REGISTER | reg; // REGISTER | READ_MASK(000A AAAA) txBuffer[1] = NRF24L01_CMD_NOP; // REVER - problema se não inicializar? uint8_t rxBuffer[2] = { 0x00, 0x00 }; NRF24L01_CSN_LOW(); // Transmit the txBuffer and receive data on rxBuffer at the time #ifdef _SSPI_ SPI_BufferRead(txBuffer, rxBuffer, 2); #else HAL_SPI_TransmitReceive( NRF24L01_Struct.hspi, txBuffer, rxBuffer, 2, NRF24L01_SPI_TIMEOUT ); #endif NRF24L01_CSN_HIGH(); return rxBuffer[1]; } void NRF24L01_WriteRegister( uint8_t reg, uint8_t value ) { uint8_t txBuffer[2], rxBuffer[2]; txBuffer[0] = NRF24L01_CMD_W_REGISTER | reg; // REGISTER | WRITE_MASK(001A AAAA) txBuffer[1] = value; // DATA to write NRF24L01_CSN_LOW(); #ifdef _SSPI_ SPI_BufferRead(txBuffer, rxBuffer, 2); #else HAL_SPI_Transmit( NRF24L01_Struct.hspi, txBuffer, 2, NRF24L01_SPI_TIMEOUT ); #endif NRF24L01_CSN_HIGH(); } // REVER qual byte vai primeiro (LSBYTE ou MSBYTE) void NRF24L01_ReadRegisterMulti(uint8_t reg, uint8_t* data, uint8_t length) { uint8_t txBuffer[ length + 1 ]; uint8_t rxBuffer[ length + 1 ]; // uint8_t *teste; // void *text; txBuffer[0] = NRF24L01_CMD_R_REGISTER | reg; for( uint8_t ind = 1 ; ind <= length ; ind++ ){ // (APAGAR) melhorar otimizacao, talvez de bug por nao inicializar txBuffer[ind] = NRF24L01_CMD_NOP; } NRF24L01_CSN_LOW(); #ifdef _SSPI_ SPI_BufferRead(txBuffer, rxBuffer, (length+1)); #else HAL_SPI_TransmitReceive( NRF24L01_Struct.hspi, txBuffer, rxBuffer, (length+1), NRF24L01_SPI_TIMEOUT ); #endif NRF24L01_CSN_HIGH(); for( uint8_t ind = 0 ; ind < length ; ind++ ){ data[ind] = rxBuffer[ ind + 1 ]; } } // REVER qual byte vai primeiro (LSBYTE ou MSBYTE) void NRF24L01_WriteRegisterMulti(uint8_t reg, uint8_t *data, uint8_t length) // REVER { uint8_t txBuffer[length + 1], rxBuffer[length + 1]; txBuffer[0] = NRF24L01_CMD_W_REGISTER | reg; for( uint8_t ind = 0 ; ind < length ; ind++ ){ txBuffer[ ind + 1 ] = data[ind]; } NRF24L01_CSN_LOW(); #ifdef _SSPI_ SPI_BufferRead(txBuffer, rxBuffer, (length+1)); #else HAL_SPI_Transmit( NRF24L01_Struct.hspi, txBuffer, (length+1), NRF24L01_SPI_TIMEOUT ); #endif NRF24L01_CSN_HIGH(); } void NRF24L01_SetRxAddress(uint8_t *adr) { NRF24L01_CE_LOW(); NRF24L01_WriteRegisterMulti(NRF24L01_REG_RX_ADDR_P1, adr, 5); NRF24L01_CE_HIGH(); } void NRF24L01_SetTxAddress(uint8_t *adr) { NRF24L01_WriteRegisterMulti(NRF24L01_REG_RX_ADDR_P0, adr, 5); NRF24L01_WriteRegisterMulti(NRF24L01_REG_TX_ADDR, adr, 5); } void NRF24L01_PowerDown(void) { NRF24L01_CE_LOW(); NRF24L01_WriteBit(NRF24L01_REG_CONFIG, NRF24L01_PWR_UP, RESET ); } void NRF24L01_PowerUP(void) { NRF24L01_WriteBit(NRF24L01_REG_CONFIG, NRF24L01_PWR_UP, SET ); } void NRF24L01_PowerUpRx(void) { /* Disable RX/TX mode */ NRF24L01_CE_LOW(); /* Clear RX buffer */ NRF24L01_FlushRx(); /* Clear interrupts */ NRF24L01_ClearInterrupts(); /* Setup RX mode */ NRF24L01_WriteRegister(NRF24L01_REG_CONFIG, NRF24L01_CONFIG | 1 << NRF24L01_PWR_UP | 1 << NRF24L01_PRIM_RX ); /* Start listening */ NRF24L01_CE_HIGH(); } void NRF24L01_PowerUpTx(void) { NRF24L01_ClearInterrupts(); NRF24L01_WriteRegister(NRF24L01_REG_CONFIG, (NRF24L01_ReadRegister( NRF24L01_REG_CONFIG ) & ~(1 << NRF24L01_PRIM_RX)) | NRF24L01_CONFIG | (1 << NRF24L01_PWR_UP)); // PWR_UP = 1, PRIM_RX = 0 } NRF24L01_Transmit_Status_t NRF24L01_Transmit(const void *data) { const uint8_t* aux; aux = data; uint8_t length = NRF24L01_Struct.PayloadSize; uint8_t txBuffer[MAXPAYLOADSIZE+1], rxBuffer[MAXPAYLOADSIZE+1];// uint8_t txBuffer[length+1]; /* Chip enable put to low, disable it */ NRF24L01_CE_LOW(); /* Clear TX FIFO from NRF24L01+ */ NRF24L01_FlushTx(); /* Send write payload command */ txBuffer[0] = NRF24L01_CMD_W_TX_PAYLOAD; /* Fill payload with data*/ for( int ind = 0 ; ind < length ; ind++ ){ // REVER se precisa iniciar txBuffer[ind+1] = aux[ind]; } /* Go to power up tx mode */ NRF24L01_PowerUpTx(); /* Settling time = 150us */ HAL_Delay(1); /* Send payload to nRF24L01+ */ NRF24L01_CSN_LOW(); /* Fill payload with data*/ #ifdef _SSPI_ SPI_BufferRead(txBuffer, rxBuffer, (length+1)); #else HAL_SPI_Transmit( NRF24L01_Struct.hspi, txBuffer, (length+1), NRF24L01_SPI_TIMEOUT ); #endif /* Disable SPI */ NRF24L01_CSN_HIGH(); /* Send data! */ NRF24L01_CE_HIGH(); HAL_Delay(1); NRF24L01_CE_LOW(); /* From J. Coliz At this point we could return from a non-blocking write, an then call the rest after an interrupt. Instead, we are going to block here until we get TX_DS(transmission completed and ack'd) or MAX_RT (maximum retries, transmission failed). Also, we'll timeout in case the radio is flaky and we get neither. In the end, the send should be blocking. It comes back in 60ms worst case. */ NRF24L01_Transmit_Status_t status = NRF24L01_Transmit_Status_Lost; uint32_t sent_at = HAL_GetTick(); const uint32_t timeout = NRF24L01_TX_TIMEOUT; do{ status = NRF24L01_GetTransmissionStatus(); }while( (HAL_GetTick() - sent_at < timeout) && (status != NRF24L01_Transmit_Status_Ok) ); NRF24L01_PowerDown(); NRF24L01_FlushTx(); return status; } void NRF24L01_GetData(uint8_t* data) // <<<<<-------------------------------- { /* Pull down chip select */ NRF24L01_CSN_LOW(); /* Send read payload command*/ uint8_t aux = NRF24L01_CMD_R_RX_PAYLOAD; #ifdef _SSPI_ SPI_SendByte(aux); #else HAL_SPI_Transmit( NRF24L01_Struct.hspi, &aux, 1, NRF24L01_SPI_TIMEOUT ); #endif #ifdef _SSPI_ SPI_BufferRead(data, data, NRF24L01_Struct.PayloadSize); #else /* Read payload */ HAL_SPI_TransmitReceive( NRF24L01_Struct.hspi, data, data, NRF24L01_Struct.PayloadSize, NRF24L01_SPI_TIMEOUT ); #endif /* Pull up chip select */ NRF24L01_CSN_HIGH(); /* Reset status register, clear RX_DR interrupt flag */ NRF24L01_WriteRegister(NRF24L01_REG_STATUS, (1 << NRF24L01_RX_DR)); } uint8_t NRF24L01_DataReady(void) { uint8_t status = NRF24L01_GetStatus(); if (NRF24L01_CHECK_BIT(status, NRF24L01_RX_DR)) { return 1; } return !NRF24L01_RxFifoEmpty(); } uint8_t NRF24L01_RxFifoEmpty(void) { uint8_t reg = NRF24L01_ReadRegister(NRF24L01_REG_FIFO_STATUS); return NRF24L01_CHECK_BIT(reg, NRF24L01_RX_EMPTY); } // funcao para tx_full // funcao para tx_empty // funcao para rx_full uint8_t NRF24L01_GetStatus(void) { uint8_t status; NRF24L01_CSN_LOW(); /* First received byte is always status register */ uint8_t aux = NRF24L01_CMD_NOP; #ifdef _SSPI_ // SPI_BufferRead(&aux, &status, 1); status = SPI_SendByte(aux); #else HAL_SPI_TransmitReceive( NRF24L01_Struct.hspi, &aux, &status, 1, NRF24L01_SPI_TIMEOUT ); #endif /* Pull up chip select */ NRF24L01_CSN_HIGH(); return status; } NRF24L01_Transmit_Status_t NRF24L01_GetTransmissionStatus(void) { uint8_t status = NRF24L01_GetStatus(); if (NRF24L01_CHECK_BIT(status, NRF24L01_TX_DS)) { /* Successfully sent */ return NRF24L01_Transmit_Status_Ok; } else if (NRF24L01_CHECK_BIT(status, NRF24L01_MAX_RT)) { /* Message lost */ return NRF24L01_Transmit_Status_Lost; } /* Still sending */ return NRF24L01_Transmit_Status_Sending; } uint8_t NRF24L01_GetRetransmissionsCount(void) { /* Low 4 bits */ return NRF24L01_ReadRegister(NRF24L01_REG_OBSERVE_TX) & 0x0F; } void NRF24L01_SetChannel(uint8_t channel) { if(channel <= 125 && channel != NRF24L01_Struct.Channel){ /* Store new channel setting */ NRF24L01_Struct.Channel = channel; /* Write channel */ NRF24L01_WriteRegister(NRF24L01_REG_RF_CH, channel); } } void NRF24L01_SetCrcLength( NRF24L01_CrcLength_t length ) { uint8_t config = NRF24L01_ReadRegister( NRF24L01_REG_CONFIG ); // "Switch uses RAM (evil!)" - J. Coliz if( length == NRF24L01_CRC_Disable ){ config &= ~( (1<< NRF24L01_CRCO) | (1<<NRF24L01_EN_CRC) ); // crc = 1byte }else if( length == NRF24L01_CRC_8 ){ config |= (1<<NRF24L01_EN_CRC); // crc = 2bytes }else{ config |= (1<<NRF24L01_EN_CRC)|(1<<NRF24L01_CRCO); } NRF24L01_WriteRegister( NRF24L01_REG_CONFIG, config ); } void NRF24L01_SetPaLevel( NRF24L01_OutputPower_t OutPwr ) { // setar power amplifier } NRF24L01_OutputPower_t NRF24L01_GetPaLevel( void ) { // get power amplifier } void setDataRate( NRF24L01_DataRate_t DataRate ) { } NRF24L01_DataRate_t NRF24L01_GetDataRate( void ) { } void NRF24L01_SetRF( NRF24L01_DataRate_t DataRate, NRF24L01_OutputPower_t OutPwr) { uint8_t tmp = 0; NRF24L01_Struct.DataRate = DataRate; NRF24L01_Struct.OutPwr = OutPwr; if(DataRate == NRF24L01_DataRate_2M){ tmp |= 1 << NRF24L01_RF_DR_HIGH; }else if(DataRate == NRF24L01_DataRate_250k){ tmp |= 1 << NRF24L01_RF_DR_LOW; } /* If 1Mbps, all bits set to 0 */ if(OutPwr == NRF24L01_OutputPower_0dBm){ tmp |= 3 << NRF24L01_RF_PWR; }else if(OutPwr == NRF24L01_OutputPower_M6dBm){ tmp |= 2 << NRF24L01_RF_PWR; }else if(OutPwr == NRF24L01_OutputPower_M12dBm){ tmp |= 1 << NRF24L01_RF_PWR; } /* If -18dBm, all bits set to 0 */ NRF24L01_WriteRegister(NRF24L01_REG_RF_SETUP, tmp); } void NRF24L01_SetAutoAck( uint8_t pipe, uint8_t state ) { if( pipe < 6 ){ uint8_t temp = NRF24L01_ReadRegister( NRF24L01_REG_DEFAULT_VAL_EN_AA ); if( state == 0x00 ){ temp &= ~(1 << pipe); }else if( state == 0x01 ){ temp |= (1 << pipe); } NRF24L01_WriteRegister( NRF24L01_REG_EN_AA, temp ); // 0xFF disable/enable all pipes }else if( pipe == 0xFF ){ uint8_t temp = NRF24L01_ReadRegister( NRF24L01_REG_DEFAULT_VAL_EN_AA ); if( state == 0x00 ){ temp &= ~(0x3F); }else if( state == 0x01 ){ temp |= (0x3F); } NRF24L01_WriteRegister( NRF24L01_REG_EN_AA, temp ); } } uint8_t NRF24L01_Available( void ) // REVER { uint8_t temp = NRF24L01_GetStatus(); uint8_t result = ( temp & (1<<NRF24L01_RX_DR) ); // fazer algo aqui para enviar o numero do pipe return result; } //uint8_t NRF24L01_Available( uint8_t* pipe_num ) // REVER //{ // uint8_t temp = NRF24L01_GetStatus(); // // uint8_t result = ( temp & (1<<NRF24L01_RX_DR) ); // // // return what pipe there is data to be read // if( pipe_num ){ // *pipe_num = ( temp & (7<<NRF24L01_RX_P_NO) ); // } // // NRF24L01_WriteRegister( NRF24L01_REG_STATUS, (1<< NRF24L01_RX_DR) ); // // // When there is payload on the acknowledge - Handle ack payload receipt // if ( temp & (1<<NRF24L01_TX_DS) ){ // NRF24L01_WriteRegister( NRF24L01_REG_STATUS, (1<<NRF24L01_TX_DS) ); // } // // return result; //} uint8_t NRF24L01_TestCarrier(void) { return (NRF24L01_ReadRegister(NRF24L01_REG_RPD) & 1); } void NRF24L01_OpenWritingPipe( uint8_t* address ) { NRF24L01_SetTxAddress( address ); NRF24L01_WriteRegister( NRF24L01_REG_RX_PW_P0, NRF24L01_Struct.PayloadSize ); /// APAGAR uint8_t teste[] = {0,0,0,0,0}; NRF24L01_ReadRegisterMulti( NRF24L01_REG_CONFIG, teste, 1 ); //APAGAR } void NRF24L01_StartListening(void) { // Power up and set primary rx NRF24L01_WriteRegister( NRF24L01_REG_CONFIG, (NRF24L01_ReadRegister(NRF24L01_REG_CONFIG) | (1<<NRF24L01_PWR_UP) | (1<<NRF24L01_PRIM_RX)) ); NRF24L01_ClearInterrupts(); // Restore the pipe0 adddress, if exists //if (pipe0_reading_address) //write_register(RX_ADDR_P0, reinterpret_cast<const uint8_t*>(&pipe0_reading_address), 5); NRF24L01_FlushRx(); NRF24L01_FlushTx(); // Go to RX MODE NRF24L01_CE_HIGH(); // only need 130us to settle HAL_Delay(10); } void NRF24L01_StopListening(void) { // Go to stand NRF24L01_CE_LOW(); NRF24L01_FlushRx(); NRF24L01_FlushTx(); } void NRF24L01_OpenReadingPipe( uint8_t number, uint8_t* address ) // REVER //TESTAR { /* "If this is pipe 0, cache the address. This is needed because openWritingPipe() will overwrite the pipe 0 address, so startListening() will have to restore it." - Coliz, J. */ if( number == 0 ){ for( int ind = 0 ; ind < 5 ; ind++ ) pipe0_reading_address[ind] = address[ind]; } if( number < 6 ){ // Pipes 0 and 1 need all 40bits if( number < 2 ){ NRF24L01_WriteRegisterMulti( (NRF24L01_REG_RX_ADDR_P0+number), address, 5 ); // First address + offset of pipes // Pipes 2,3,4,5 need just the LSB byte }else{ NRF24L01_WriteRegister( (NRF24L01_REG_RX_ADDR_P0+number), address[4] ); // The last byte is the LSByte } } } uint8_t NRF24L01_Read(void* data) { uint8_t txBuffer[ NRF24L01_Struct.PayloadSize + 1 ]; /* Set buffer with read command and some data to just shift */ txBuffer[0] = NRF24L01_CMD_R_RX_PAYLOAD; for( uint8_t ind = 0 ; ind < NRF24L01_Struct.PayloadSize ; ind++ ) // APAGAR - ver se array nao iniciado da erro txBuffer[ind+1] = 0x00; uint8_t *rxBuffer = (uint8_t*)data; // BUG troca de tipo de ponteiros /* Pull down chip select */ NRF24L01_CSN_LOW(); /* Read payload */ #ifdef _SSPI_ SPI_BufferRead(txBuffer, rxBuffer, (NRF24L01_Struct.PayloadSize+1)); #else HAL_SPI_TransmitReceive( NRF24L01_Struct.hspi, txBuffer, rxBuffer, (NRF24L01_Struct.PayloadSize+1), NRF24L01_SPI_TIMEOUT ); // (TROCAR) ordem caso de erro #endif // printData("rxBuffer", rxBuffer, (NRF24L01_Struct.PayloadSize+1)); // printChar("rxBuffer", rxBuffer, (NRF24L01_Struct.PayloadSize+1)); /* Pull up chip select */ NRF24L01_CSN_HIGH(); /* Reset status register, clear RX_DR interrupt flag */ NRF24L01_WriteRegister(NRF24L01_REG_STATUS, (1 << NRF24L01_RX_DR)); return (NRF24L01_ReadRegister(NRF24L01_REG_FIFO_STATUS) & (1<<NRF24L01_RX_EMPTY)); } uint8_t NRF24L01_GetPayloadSize(void) { return NRF24L01_Struct.PayloadSize; } uint8_t NRF24L01_GetDynamicPayloadSize(void) { } void NRF24L01_SetRetries(uint8_t delay, uint8_t count) { } |
from: https://eroro.tistory.com/582
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
/* Includes ------------------------------------------------------------------*/ #include "usr_mcp4251.h" /* Private variables ---------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ void MCP4251_configuration(void) { SPI2_CE0_HIGH(); SPI2_CE1_HIGH(); DelayMs(10); SPIx_Init(SPI_2); } /* 00h - Volatile Wiper 0 Write Data 0000 00xx xxxx xxxx Read Data 0000 11xx xxxx xxxx Increment Wiper 0000 0100 Decrement Wiper 0000 1000 01h - Volatile Wiper 1 Write Data 0001 00xx xxxx xxxx Read Data 0001 11xx xxxx xxxx Increment Wiper 0001 0100 Decrement Wiper 0001 1000 02h - Reserved 03h - Reserved 04h - Volatile TCON Write Data 0100 00xx xxxx xxxx Read Data 0100 11xx xxxx xxxx 05h - Status Register Read Data 0101 11xx xxxx xxxx 06h ~ 0Fh - Reserved #define MCP4131_WRITE (0x00 << 2) #define MCP4131_READ (0x03 << 2) #define MCP4131_WIPER_SHIFT 4 int address = chan->channel << MCP4131_WIPER_SHIFT; --Write-- data->buf[0] = address << MCP4131_WIPER_SHIFT; data->buf[0] |= MCP4131_WRITE | (val >> 8); data->buf[1] = val & 0xFF; --Read-- data->buf[0] = (address << MCP4131_WIPER_SHIFT) | MCP4131_READ; data->buf[1] = 0; */ /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ u8 MCP4251_Read(uint8_t ch, uint8_t Addr, uint8_t reg) { u32 SPITimeout = SPI_FLAG_TIMEOUT; if(ch == 1){ SPI2_CE0_LOW(); SPI2_CE0_HIGH(); } else{ SPI2_CE1_LOW(); SPI2_CE1_HIGH(); } return 0; } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ u8 SPI_transfer(uint8_t reg) { u32 SPITimeout = SPI_FLAG_TIMEOUT; /* Loop while DR register in not emplty */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET){ if((SPITimeout--) == 0) return 1; } /* Send u8 through the SPI1 peripheral */ SPI_I2S_SendData(SPI2, (uint16_t)reg); return 0; } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ void MCP4251_DigitalPotWiperIncrement(u8 potNum) { u8 cmdu8 = 0x00; SPI2_CE0_LOW(); //CE 0 Low if (potNum){ cmdu8 = ADDRESS_WIPER_1 | COMMAND_INCREMENT; SPI_transfer(cmdu8); } else{ cmdu8 = ADDRESS_WIPER_0 | COMMAND_INCREMENT; SPI_transfer(cmdu8); } SPI2_CE0_HIGH(); //CE 0 High } void MCP4251_DigitalPotWiperDecrement(u8 potNum) { u8 cmdu8 = 0x00; SPI2_CE0_LOW(); //CE 0 Low if (potNum){ cmdu8 = ADDRESS_WIPER_1 | COMMAND_DECREMENT; SPI_transfer(cmdu8); } else{ cmdu8 = ADDRESS_WIPER_0 | COMMAND_DECREMENT; SPI_transfer(cmdu8); } SPI2_CE0_HIGH(); //CE 0 High } void MCP4251_DigitalPotSetWiperPosition(u8 potNum, u32 value) { u8 cmdu8 = 0x00; u8 datau8 = 0x00; if (value > 255) cmdu8 |= 0x01; else datau8 = (u8)(value & 0X00FF); SPI2_CE0_LOW(); //CE 0 Low DelayUs(10); if (potNum) { cmdu8 = cmdu8 | ADDRESS_WIPER_1 | COMMAND_WRITE; SPI_transfer(cmdu8); SPI_transfer(datau8); } else { cmdu8 = cmdu8 | ADDRESS_WIPER_0 | COMMAND_WRITE; SPI_transfer(cmdu8); SPI_transfer(datau8); } DelayUs(10); DEBUGPRINT("cmdu8 %d, datau8 %d\r\n", cmdu8, datau8 ); SPI2_CE0_HIGH(); //CE 0 High } void MCP4251_DigitalPotSetWiperMin(u8 potNum) { if (potNum) MCP4251_DigitalPotSetWiperPosition(1, 0); else MCP4251_DigitalPotSetWiperPosition(0, 0); } void MCP4251_DigitalPotSetWiperMax(u8 potNum) { if (potNum) MCP4251_DigitalPotSetWiperPosition(1, 256); else MCP4251_DigitalPotSetWiperPosition(0, 256); } void MCP4251_DigitalPotSetWiperMid(u8 potNum) { if (potNum) MCP4251_DigitalPotSetWiperPosition(1, 128); else MCP4251_DigitalPotSetWiperPosition(0, 128); } uint16_t MCP4251_DigitalPotReadWiperPosition(u8 potNum) { u8 cmdu8 = 0x00; u8 hu8 = 0x00; u8 lu8 = 0x00; SPI2_CE0_LOW(); //CE 0 Low if (potNum) { cmdu8 = ADDRESS_WIPER_1 | COMMAND_READ; hu8 = SPI_transfer(cmdu8); lu8 = SPI_transfer(DUMMY_DATA); } else { cmdu8 = ADDRESS_WIPER_0 | COMMAND_READ; hu8 = SPI_transfer(cmdu8); lu8 = SPI_transfer(DUMMY_DATA); } SPI2_CE0_HIGH(); //CE 0 High return ((uint16_t)hu8 << 8 | (uint16_t)lu8) & BITMASK_READ_DATA_REGISTER; } uint16_t MCP4251_DigitalPotReadStatusRegister() { u8 cmdu8 = 0x00; u8 hu8 = 0x00; u8 lu8 = 0x00; SPI2_CE0_LOW(); //CE 0 Low cmdu8 = ADDRESS_STATUS | COMMAND_READ; hu8 = SPI_transfer(cmdu8); lu8 = SPI_transfer(DUMMY_DATA); SPI2_CE0_HIGH(); //CE 0 High return ((uint16_t)hu8 << 8 | (uint16_t)lu8) & BITMASK_READ_DATA_REGISTER; } uint16_t MCP4251_DigitalPotReadTconRegister() { u8 cmdu8 = 0x00; u8 hu8 = 0x00; u8 lu8 = 0x00; SPI2_CE0_LOW(); //CE 0 Low cmdu8 = ADDRESS_TCON | COMMAND_READ; hu8 = SPI_transfer(cmdu8); lu8 = SPI_transfer(DUMMY_DATA); SPI2_CE0_HIGH(); //CE 0 High return ((uint16_t)hu8 << 8 | (uint16_t)lu8) & BITMASK_READ_DATA_REGISTER; } void MCP4251_DigitalPotWriteTconRegister(uint16_t value) { u8 cmdu8 = 0x00; u8 datau8 = 0x00; if (value > 255) cmdu8 |= 0x01; else datau8 = (u8)(value & 0X00FF); SPI2_CE0_LOW(); //CE 0 Low cmdu8 = cmdu8 | ADDRESS_TCON | COMMAND_WRITE; SPI_transfer(cmdu8); SPI_transfer(datau8); SPI2_CE0_HIGH(); //CE 0 High } void MCP4251_DigitalPotStartup(u8 potNum) { uint16_t tconData = MCP4251_DigitalPotReadTconRegister(); u8 hu8 = (uint8_t)tconData >> 8; u8 lu8 = (uint8_t)tconData & 0xff; if (potNum) lu8 = lu8 | BITMASK_POT1_STARTUP; else lu8 = lu8 | BITMASK_POT0_STARTUP; tconData = (uint16_t)hu8 << 8 | (uint16_t)lu8; MCP4251_DigitalPotWriteTconRegister(tconData); } void MCP4251_DigitalPotShutdown(u8 potNum) { uint16_t tconData = MCP4251_DigitalPotReadTconRegister(); u8 hu8 = (uint8_t)tconData >> 8; u8 lu8 = (uint8_t)tconData & 0xff; if (potNum) lu8 = lu8 & ~BITMASK_POT1_STARTUP; else lu8 = lu8 & ~BITMASK_POT0_STARTUP; tconData = (uint16_t)hu8 << 8 | (uint16_t)lu8; MCP4251_DigitalPotWriteTconRegister(tconData); } void MCP4251_DigitalPotTerminalBConnect(u8 potNum) { uint16_t tconData = MCP4251_DigitalPotReadTconRegister(); u8 hu8 = (uint8_t)tconData >> 8; u8 lu8 = (uint8_t)tconData & 0xff; if (potNum) lu8 = lu8 | BITMASK_POT1_B_TERMINAL_CONNECT; else lu8 = lu8 | BITMASK_POT0_B_TERMINAL_CONNECT; tconData = (uint16_t)hu8 << 8 | (uint16_t)lu8; MCP4251_DigitalPotWriteTconRegister(tconData); } void MCP4251_DigitalPotTerminalBDisconnect(u8 potNum) { uint16_t tconData = MCP4251_DigitalPotReadTconRegister(); u8 hu8 = (uint8_t)tconData >> 8; u8 lu8 = (uint8_t)tconData & 0xff; if (potNum) lu8 = lu8 & ~BITMASK_POT1_B_TERMINAL_CONNECT; else lu8 = lu8 & ~BITMASK_POT0_B_TERMINAL_CONNECT; tconData = (uint16_t)hu8 << 8 | (uint16_t)lu8; MCP4251_DigitalPotWriteTconRegister(tconData); } void MCP4251_DigitalPotTerminalAConnect(u8 potNum) { uint16_t tconData = MCP4251_DigitalPotReadTconRegister(); u8 hu8 = (uint8_t)tconData >> 8; u8 lu8 = (uint8_t)tconData & 0xff; if (potNum) lu8 = lu8 | BITMASK_POT1_A_TERMINAL_CONNECT; else lu8 = lu8 | BITMASK_POT0_A_TERMINAL_CONNECT; tconData = (uint16_t)hu8 << 8 | (uint16_t)lu8; MCP4251_DigitalPotWriteTconRegister(tconData); } void MCP4251_DigitalPotTerminalADisconnect(u8 potNum) { uint16_t tconData = MCP4251_DigitalPotReadTconRegister(); u8 hu8 = (uint8_t)tconData >> 8; u8 lu8 = (uint8_t)tconData & 0xff; if (potNum) lu8 = lu8 & ~BITMASK_POT1_A_TERMINAL_CONNECT; else lu8 = lu8 & ~BITMASK_POT0_A_TERMINAL_CONNECT; tconData = (uint16_t)hu8 << 8 | (uint16_t)lu8; MCP4251_DigitalPotWriteTconRegister(tconData); } void MCP4251_DigitalPotWiperConnect(u8 potNum) { uint16_t tconData = MCP4251_DigitalPotReadTconRegister(); u8 hu8 = (uint8_t)tconData >> 8; u8 lu8 = (uint8_t)tconData & 0xff; if (potNum) lu8 = lu8 | BITMASK_POT1_WIPER_TERMINAL_CONNECT; else lu8 = lu8 | BITMASK_POT0_WIPER_TERMINAL_CONNECT; tconData = (uint16_t)hu8 << 8 | (uint16_t)lu8; MCP4251_DigitalPotWriteTconRegister(tconData); } void MCP4251_DigitalPotWiperDisconnect(u8 potNum) { uint16_t tconData = MCP4251_DigitalPotReadTconRegister(); u8 hu8 = (uint8_t)tconData >> 8; u8 lu8 = (uint8_t)tconData & 0xff; if (potNum) lu8 = lu8 & ~BITMASK_POT1_WIPER_TERMINAL_CONNECT; else lu8 = lu8 & ~BITMASK_POT0_WIPER_TERMINAL_CONNECT; tconData = (uint16_t)hu8 << 8 | (uint16_t)lu8; MCP4251_DigitalPotWriteTconRegister(tconData); } void MCP4251_DigitalPotInitTcon() { uint16_t tconData = MCP4251_DigitalPotReadTconRegister(); u8 hu8 = (uint8_t)tconData >> 8; u8 lu8 = (uint8_t)tconData & 0xff; lu8 = lu8 | DUMMY_DATA; tconData = (uint16_t)hu8 << 8 | (uint16_t)lu8; MCP4251_DigitalPotWriteTconRegister(tconData); } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ u8 MCP4251_Test(void) { u8 i = 0; while(1){ for(i=0; i<=255; i++){ StatusLED1toggle(); StatusLED2toggle(); StatusLED3toggle(); StatusLED4toggle(); MCP4251_DigitalPotSetWiperPosition(1, i); DelayMs(1); } } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
#ifndef __USR_MCP4251_H #define __USR_MCP4251_H #include "main.h" /* Private define ------------------------------------------------------------*/ /* 8BIT COMMAND AD3 AC2 AD1 AD0 C1 C0 D9 D8 16BIT COMMAND AD3 AC2 AD1 AD0 C1 C0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 C1 C0 0 0 WRITE DATA 0 1 INCR 1 0 DECR 1 1 READ DATA */ #define ADDRESS_WIPER_0 0x00 #define ADDRESS_WIPER_1 0x10 #define ADDRESS_TCON 0x40 #define ADDRESS_STATUS 0x50 #define COMMAND_WRITE 0x00 #define COMMAND_INCREMENT 0x04 #define COMMAND_DECREMENT 0x08 #define COMMAND_READ 0x0C #define DUMMY_DATA 0xFF #define BITMASK_READ_DATA_REGISTER 0X01FF //B0000000111111111 #define TCON0OFF1ON 0xF0 #define TCON0ON1OFF 0x0F #define TCON0OFF1OFF 0x00 #define TCON0ON1ON 0xFF #define BITMASK_POT0_STARTUP 0x08 #define BITMASK_POT1_STARTUP 0x80 #define BITMASK_POT0_B_TERMINAL_CONNECT 0x01 #define BITMASK_POT1_B_TERMINAL_CONNECT 0x10 #define BITMASK_POT0_WIPER_TERMINAL_CONNECT 0x02 #define BITMASK_POT1_WIPER_TERMINAL_CONNECT 0x20 #define BITMASK_POT0_A_TERMINAL_CONNECT 0x04 #define BITMASK_POT1_A_TERMINAL_CONNECT 0x40 #define MCP4251_FLAG_TIMEOUT 0x1000 /* Private typedef -----------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Function define ------------------------------------------------------------*/ void MCP4251_configuration(void); u8 MCP4251_Write(uint8_t ch, uint8_t Addr, uint8_t reg); u8 MCP4251_Test(void); #endif //__USR_MCP4251_H |
——————————————————————————————————————–
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
/* Includes ------------------------------------------------------------------*/ #include "main.h" /* Private variables ---------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ void MCP4716_configuration(void) { I2CBus_Init(I2C_1, 0x00, CLK_100kHZ); } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ u8 MCP4716_WriteCMD(uint8_t ch, uint16_t reg) { if(ch == 1){ while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)); /* Start */ I2C_GenerateSTART(I2C1, ENABLE); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); I2C_Send7bitAddress(I2C1, MCP4716A0_Address, I2C_Direction_Transmitter); //??MCP4726???? 0xc0 ?,0xc1 ? while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* Send data */ I2C_SendData(I2C1, reg); while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); /* Stop */ I2C_GenerateSTOP(I2C1, ENABLE); } else{ while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)); /* Start */ I2C_GenerateSTART(I2C1, ENABLE); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); I2C_Send7bitAddress(I2C1, MCP4716A3_Address, I2C_Direction_Transmitter); //??MCP4726???? 0xc0 ?,0xc1 ? while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* Send data */ I2C_SendData(I2C1, reg); while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); /* Stop */ I2C_GenerateSTOP(I2C1, ENABLE); } return 0; } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ u8 MCP4716_WriteDIG(uint8_t ch, uint16_t reg) { u8 data_H=0, data_L=0; data_H = ( 0x0F00 & reg) >> 8; data_L = 0X00FF & reg ; if(ch == 1){ while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)); /* Start */ I2C_GenerateSTART(I2C1, ENABLE); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); I2C_Send7bitAddress(I2C1, MCP4716A0_Address, I2C_Direction_Transmitter); //??MCP4726???? 0xc0 ?,0xc1 ? while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* Send data */ I2C_SendData(I2C1, data_H); while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); I2C_SendData(I2C1, data_L); while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); /* Stop */ I2C_GenerateSTOP(I2C1, ENABLE); } else{ while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)); /* Start */ I2C_GenerateSTART(I2C1, ENABLE); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); I2C_Send7bitAddress(I2C1, MCP4716A3_Address, I2C_Direction_Transmitter); //??MCP4726???? 0xc0 ?,0xc1 ? while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* Send data */ I2C_SendData(I2C1, data_H); while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); I2C_SendData(I2C1, data_L); while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); /* Stop */ I2C_GenerateSTOP(I2C1, ENABLE); } return 0; } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ u8 MCP4716_WriteDAT_Voltage(uint8_t ch, uint16_t reg) { u8 temp = 0; u16 Dn = 0; if(reg >= 3300) reg = 3300; Dn = ( 4095 * reg) / 3300; temp = (0x0F00 & Dn) >> 8; if(ch == 1){ while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)); /* Start */ I2C_GenerateSTART(I2C1, ENABLE); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); I2C_Send7bitAddress(I2C1, MCP4716A0_Address, I2C_Direction_Transmitter); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* Send data */ I2C_SendData(I2C1, temp); while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); I2C_SendData(I2C1, Dn); while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); /* Stop */ I2C_GenerateSTOP(I2C1, ENABLE); } else{ while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)); /* Start */ I2C_GenerateSTART(I2C1, ENABLE); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); I2C_Send7bitAddress(I2C1, MCP4716A3_Address, I2C_Direction_Transmitter); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* Send data */ I2C_SendData(I2C1, temp); while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); I2C_SendData(I2C1, Dn); while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); /* Stop */ I2C_GenerateSTOP(I2C1, ENABLE); } return 0; } /******************************************************************************* * Function Name : * Description : * Parameters : None * Return : None * Description : *******************************************************************************/ u8 MCP4716_Test(void) { u16 i = 0; MCP4716_WriteCMD(1, 0x98); MCP4716_WriteCMD(2, 0x98); DelayMs(10); MCP4716_WriteDAT_Voltage(1, 3300); MCP4716_WriteDAT_Voltage(2, 3300); while(1) { for(i=0; i<=3301; i++){ StatusLED1toggle(); StatusLED2toggle(); StatusLED3toggle(); StatusLED4toggle(); MCP4716_WriteDAT_Voltage(1, i); MCP4716_WriteDAT_Voltage(2, i); // DelayUs(10000); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
#ifndef __USR_MCP4716_H #define __USR_MCP4716_H #include "main.h" /* Private define ------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /* Command Code VREF1 VREF0 PD1 PD0 G 1. Command C2 C1 C0 0 0 x Write Volatile DAC Register Command 0 1 0 Write Volatile Memory Command 0 1 1 Write All Memory Command 1 0 0 Write Volatile Configuration Bits Command 2. Resistor Ladder Voltage Reference (VRL) Selection bits 0x = VDD (Unbuffered) 10 = VREF pin (Unbuffered) 11 = VREF pin (Buffered) 3. Power-Down Selection bits When the DAC is powered down, most of the internal circuits are powered off and the op amp is disconnected from the VOUT pin. 00 = Not Powered Down (Normal operation) 01 = Powered Down – VOUT is loaded with 1 kO resistor to ground. 10 = Powered Down – VOUT is loaded with 100 kO resistor to ground. 11 = Powered Down – VOUT is loaded with 500 kO resistor to ground. 4. Gain Selection bit 0 = 1x (gain of 1) 1 = 2x (gain of 2). Not applicable when VDD is used as VRL VREF1 VREF0 PD1 PD0 G POR Event 0 0 0 0 0 When VDD transitions from VDD < VPOR to VDD > VPOR BOR Event 0 0 1 1 0 When VDD transitions from VDD > VBOR to VDD < VBOR DataSheet Block Diagram C2 C1 C0 VREF1 VREF0 PD1 PD0 G 1 0 0 1 1 0 0 0 => 0x98 Write Volatile Configuration Bits Command VREF pin (Buffered) => This Sche. DON'T CARE Not Powered Down (Normal operation) 1x (gain of 1) */ /* Private variables ---------------------------------------------------------*/ //Write 0, Read 1 #define MCP4716A0_Address 0xC0//1100 000x x = Read/Write #define MCP4716A1_Address 0xC2//1100 001x x = Read/Write #define MCP4716A2_Address 0xC4//1100 010x x = Read/Write #define MCP4716A3_Address 0xC6//1100 011x x = Read/Write #define MCP4716A4_Address 0xC8//1100 100x x = Read/Write #define MCP4716A5_Address 0xCA//1100 101x x = Read/Write #define MCP4716A6_Address 0xCC//1100 110x x = Read/Write #define MCP4716A7_Address 0xCE//1100 111x x = Read/Write #define MCP4716A0_ReadAddress MCP4716A0_Address|0x01//1100 000x x = Read/Write #define MCP4716A1_ReadAddress MCP4716A1_Address|0x01//1100 001x x = Read/Write #define MCP4716A2_ReadAddress MCP4716A2_Address|0x01//1100 010x x = Read/Write #define MCP4716A3_ReadAddress MCP4716A3_Address|0x01//1100 011x x = Read/Write #define MCP4716A4_ReadAddress MCP4716A4_Address|0x01//1100 100x x = Read/Write #define MCP4716A5_ReadAddress MCP4716A5_Address|0x01//1100 101x x = Read/Write #define MCP4716A6_ReadAddress MCP4716A6_Address|0x01//1100 110x x = Read/Write #define MCP4716A7_ReadAddress MCP4716A7_Address|0x01//1100 111x x = Read/Write /* Function define ------------------------------------------------------------*/ void MCP4716_configuration(void); u8 MCP4716_WriteCMD(uint8_t ch, uint16_t reg); u8 MCP4716_WriteDIG(uint8_t ch, uint16_t reg); u8 MCP4716_WriteDAT_Voltage(uint8_t ch, uint16_t reg); u8 MCP4716_Test(void); #endif //__USR_MCP4716_H |
https://eroro.tistory.com/542 ADC로 전류값을 읽어온 후 180mA로 타겟값을 맞췄습니다. (미제어시 125mA ~ 170mA 정도 소요) => arm에서 제공하는 arm_cortexMxxx_math.lib를 사용
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
#define TAGET_ADC 1000 void PID_ADC(uint8_t *chpADC, uint8_t chSize) { Get_RAWADC(s_chpBuf[s_ADCpointer++]); PID_CurrentControl(Average(s_chpBuf, ADCCNT, 1), TAGET_ADC); if(s_ADCpointer >= ADCCNT){ s_ADCpointer = 0; } } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void Display(void) { DEBUGPRINT("ADC_Volt %d, %fV, ", Average(s_chpBuf, ADCCNT, 0), Voltage_Calc(Average(s_chpBuf, ADCCNT, 0))); DEBUGPRINT("ADC_Curr %d, %fA, ", Average(s_chpBuf, ADCCNT, 1), Current_Calc(Average(s_chpBuf, ADCCNT, 1))); DEBUGPRINT("ADC_Temp %d, %d \r\n", Average(s_chpBuf, ADCCNT, 2), __LL_ADC_CALC_TEMPERATURE(3300, Average(s_chpBuf, ADCCNT, 2), LL_ADC_RESOLUTION)); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void Set_DutyCycle(uint32_t D) { uint32_t P; /* Pulse duration */ if(D == 0){ LL_TIM_OC_SetCompareCH1(TIM1, PWMRANGE); } else{ P = PWMRANGE - D; LL_TIM_OC_SetCompareCH1(TIM1, P); } } /* Includes ------------------------------------------------------------------*/ #include "usr_pid.h" #include "usr_usart.h" #include "usr_timer.h" #include "usr_system.h" /* Private variables ---------------------------------------------------------*/ arm_pid_instance_f32 PID_Current; /* Current */ #define PID_PARAM_KP 100 /* Proporcional */ #define PID_PARAM_KI 0.2 /* Integral */ #define PID_PARAM_KD 10 /* Derivative */ /* Private macro -------------------------------------------------------------*/ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void Config_PID(void) { /* Set this for your needs */ PID_Current.Kp = PID_PARAM_KP; /* Proporcional */ PID_Current.Ki = PID_PARAM_KI; /* Integral */ PID_Current.Kd = PID_PARAM_KD; /* Derivative */ /* Initialize PID system, float32_t format */ arm_pid_init_f32(&PID_Current, 1); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void PID_CurrentControl(float a_fCurr, float a_fTargetCurr) { float pid_error = 0; /* Duty cycle for PWM */ float duty = 0; /* Calculate error */ pid_error = a_fTargetCurr - a_fCurr; /* Calculate PID here, argument is error */ /* Output data will be returned, we will use it as duty cycle parameter */ duty = arm_pid_f32(&PID_Current, pid_error); Set_DutyCycle(duty); } |
https://eroro.tistory.com/531 사용 MCU : STM32L432 SPI Slave Mode에서 입력된 데이터를 파싱하고 처리하는 데도 연달아 데이터가 계속 들어오다보니 어느순간 SPI가 죽어버렸습니다. (SPI Flash의 쓰기 같은 경우 데이터를 넣고 나서 완료되었는 지 […]
from: https://eroro.tistory.com/500 \Drivers\CMSIS\DSP_Lib\Source\ControllerFunctions 안에 arm_pid_init_f32.c 파일을 Merge 시키거나 arm_math 파일만을 묶어서 라이브러리로 만들어 추가해도 됩니다. 실제 사용시에는 다양한 값을 받아서 PID 제어를 하면 될 듯 싶습니다. 조금 더 부드럽게 […]
from: https://eroro.tistory.com/499
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
void main(void) { ACCGyroAxis_TypeDef ACCAxis, GyroAxis; MagnetAxis_TypeDef MagnetAxis; float fPress, ftemperature; float fBatt; uint16_t Batt_Percent; LSM6DSL_ACCGyroInit(); LIS2MDL_MagnetInit(); LPS22HB_TempPreInit(); LSM6DSL_ACCGyroEnable(); LIS2MDL_MagnetEnable(); LPS22HB_TempPreEnable(); LSM6DSL_ACCGyroSetting(); LIS2MDL_MagnetSetting(); while(1) { MeasurementSensorData(5, &ACCAxis, &GyroAxis, &MagnetAxis, &fPress, &ftemperature, &fBatt, &Batt_Percent); } } /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G 0.061 /**< Sensitivity value for 2 g full scale [mg/LSB] */ #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G 0.122 /**< Sensitivity value for 4 g full scale [mg/LSB] */ #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G 0.244 /**< Sensitivity value for 8 g full scale [mg/LSB] */ #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G 0.488 /**< Sensitivity value for 16 g full scale [mg/LSB] */ #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS 04.375 /**< Sensitivity value for 125 dps full scale [mdps/LSB] */ #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS 08.750 /**< Sensitivity value for 245 dps full scale [mdps/LSB] */ #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS 17.500 /**< Sensitivity value for 500 dps full scale [mdps/LSB] */ #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS 35.000 /**< Sensitivity value for 1000 dps full scale [mdps/LSB] */ #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS 70.000 /**< Sensitivity value for 2000 dps full scale [mdps/LSB] */ #define LSM6DSL_ACC_SENSITIVITY LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G #define LSM6DSL_GYRO_SENSITIVITY LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS typedef enum { eModeACC = 0, eModeGyro, } eModeACCGyro_TypeDef; typedef struct { int32_t ACCGyro_X; int32_t ACCGyro_Y; int32_t ACCGyro_Z; }ACCGyroAxis_TypeDef; //#define LSM6DSL_RESERVED 0x00 #define LSM6DSL_FUNC_CFG_ACCESS 0x01 //Embedded functions //#define LSM6DSL_RESERVED 0x02 //#define LSM6DSL_RESERVED 0x03 #define LSM6DSL_SENSOR_SYNC_TIME_FRAME 0x04 //r/w #define LSM6DSL_SENSOR_SYNC_RES_RATIO 0x05 //r/w #define LSM6DSL_FIFO_CTRL1 0x06 //r/w #define LSM6DSL_FIFO_CTRL2 0x07 //r/w #define LSM6DSL_FIFO_CTRL3 0x08 //r/w #define LSM6DSL_FIFO_CTRL4 0x09 //r/w #define LSM6DSL_FIFO_CTRL5 0x0A //r/w #define LSM6DSL_DRDY_PULSE_CFG_G 0x0B //r/w //#define LSM6DSL_RESERVED 0x0C #define LSM6DSL_INT1_CTRL 0x0D //r/w INT1 pin control #define LSM6DSL_INT2_CTRL 0x0E //r/w INT2 pin control #define LSM6DSL_WHO_AM_I 0x0F //r Who I am ID #define LSM6DSL_CTRL1_XL 0x10 //r/w #define LSM6DSL_CTRL2_G 0x11 //r/w #define LSM6DSL_CTRL3_C 0x12 //r/w #define LSM6DSL_CTRL4_C 0x13 //r/w #define LSM6DSL_CTRL5_C 0x14 //r/w #define LSM6DSL_CTRL6_C 0x15 //r/w #define LSM6DSL_CTRL7_G 0x16 //r/w #define LSM6DSL_CTRL8_XL 0x17 //r/w #define LSM6DSL_CTRL9_XL 0x18 //r/w #define LSM6DSL_CTRL10_C 0x19 //r/w #define LSM6DSL_MASTER_CONFIG 0x1A //r/w #define LSM6DSL_WAKE_UP_SRC 0x1B //r #define LSM6DSL_TAP_SRC 0x1C //r Interrupt registers #define LSM6DSL_D6D_SRC 0x1D //r #define LSM6DSL_STATUS_REG 0x1E //r //#define LSM6DSL_RESERVED 0x1F #define LSM6DSL_OUT_TEMP_L 0x20 //r Temperature output #define LSM6DSL_OUT_TEMP_H 0x21 //r data registers #define LSM6DSL_OUTX_L_G 0x22 //r GYRO #define LSM6DSL_OUTX_H_G 0x23 //r #define LSM6DSL_OUTY_L_G 0x24 //r #define LSM6DSL_OUTY_H_G 0x25 //r #define LSM6DSL_OUTZ_L_G 0x26 //r #define LSM6DSL_OUTZ_H_G 0x27 //r #define LSM6DSL_OUTX_L_XL 0x28 //r ACC #define LSM6DSL_OUTX_H_XL 0x29 //r #define LSM6DSL_OUTY_L_XL 0x2A //r #define LSM6DSL_OUTY_H_XL 0x2B //r #define LSM6DSL_OUTZ_L_XL 0x2C //r #define LSM6DSL_OUTZ_H_XL 0x2D //r #define LSM6DSL_SENSORHUB1_REG 0x2E //r #define LSM6DSL_SENSORHUB2_REG 0x2F //r #define LSM6DSL_SENSORHUB3_REG 0x30 //r #define LSM6DSL_SENSORHUB4_REG 0x31 //r #define LSM6DSL_SENSORHUB5_REG 0x32 //r #define LSM6DSL_SENSORHUB6_REG 0x33 //r #define LSM6DSL_SENSORHUB7_REG 0x34 //r #define LSM6DSL_SENSORHUB8_REG 0x35 //r #define LSM6DSL_SENSORHUB9_REG 0x36 //r #define LSM6DSL_SENSORHUB10_REG 0x37 //r #define LSM6DSL_SENSORHUB11_REG 0x38 //r #define LSM6DSL_SENSORHUB12_REG 0x39 //r #define LSM6DSL_FIFO_STATUS1 0x3A //r #define LSM6DSL_FIFO_STATUS2 0x3B //r #define LSM6DSL_FIFO_STATUS3 0x3C //r #define LSM6DSL_FIFO_STATUS4 0x3D //r #define LSM6DSL_FIFO_DATA_OUT_L 0x3E //r FIFO data output #define LSM6DSL_FIFO_DATA_OUT_H 0x3F //r #define LSM6DSL_TIMESTAMP0_REG 0x40 //r #define LSM6DSL_TIMESTAMP1_REG 0x41 //r #define LSM6DSL_TIMESTAMP2_REG 0x42 //r/w //#define LSM6DSL_RESERVED 0x43 ~ 0x48 #define LSM6DSL_STEP_TIMESTAMP_L 0x49 //r Step counter #define LSM6DSL_STEP_TIMESTAMP_H 0x4A //r timestamp registers #define LSM6DSL_STEP_COUNTER_L 0x4B //r Step counte0xoutput #define LSM6DSL_STEP_COUNTER_H 0x4C //r registers #define LSM6DSL_SENSORHUB13_REG 0x4D //r #define LSM6DSL_SENSORHUB14_REG 0x4E //r #define LSM6DSL_SENSORHUB15_REG 0x4F //r #define LSM6DSL_SENSORHUB16_REG 0x50 //r #define LSM6DSL_SENSORHUB17_REG 0x51 //r #define LSM6DSL_SENSORHUB18_REG 0x52 //r #define LSM6DSL_FUNC_SRC1 0x53 //r #define LSM6DSL_FUNC_SRC2 0x54 //r #define LSM6DSL_WRIST_TILT_IA 0x55 //r Interrupt register //#define LSM6DSL_RESERVED - 56-57 - #define LSM6DSL_TAP_CFG 0x58 //r/w #define LSM6DSL_TAP_THS_6D 0x59 //r/w #define LSM6DSL_INT_DUR2 0x5A //r/w #define LSM6DSL_WAKE_UP_THS 0x5B //r/w #define LSM6DSL_WAKE_UP_DU0x0x5C //r/w #define LSM6DSL_FREE_FALL 0x5D //r/w #define LSM6DSL_MD1_CFG 0x5E //r/w #define LSM6DSL_MD2_CFG 0x5F //r/w #define LSM6DSL_MASTER_CMD_CODE 0x60 //r/w #define LSM6DSL_SENS_SYNC_SPI_ERROR_CODE 0x61 //r/w //#define LSM6DSL_RESERVED - 62-65 - Reserved #define LSM6DSL_OUT_MAG_RAW_X_L 0x66 //r #define LSM6DSL_OUT_MAG_RAW_X_H 0x67 //r #define LSM6DSL_OUT_MAG_RAW_Y_L 0x68 //r #define LSM6DSL_OUT_MAG_RAW_Y_H 0x69 //r #define LSM6DSL_OUT_MAG_RAW_Z_L 0x6A //r #define LSM6DSL_OUT_MAG_RAW_Z_H 0x6B //r //#define LSM6DSL_RESERVED - 6C-72 - #define LSM6DSL_X_OFS_US0x0x73 //r/w #define LSM6DSL_Y_OFS_US0x0x74 //r/w #define LSM6DSL_Z_OFS_US0x0x75 //r/w //#define LSM6DSL_RESERVED - 76-7F - /* Private macro ------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes ------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ extern void UART1_printf(const char *fmt,...); ACCGyroAxis_TypeDef gstACCAxis; ACCGyroAxis_TypeDef gstGyroAxis; /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LSM6DSL_ACCGyroInit(void) { uint8_t Data[10]; Data[0] = 0x0C; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL3_C, Data, 1); Data[0] = 0x00; SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_WHO_AM_I, Data, 1); Data[0] = 0x6A; SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL3_C, Data, 1); Data[0] = 0x0C; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL3_C, Data, 1); SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL3_C, Data, 1); Data[0] = 0x4C; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL3_C, Data, 1); SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_FIFO_CTRL5, Data, 1); Data[0] = 0x00; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_FIFO_CTRL5, Data, 1); SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL1_XL, Data, 1); Data[0] = 0x00; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL1_XL, Data, 1); SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL1_XL, Data, 1); Data[0] = 0x00; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL1_XL, Data, 1); SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL4_C, Data, 1); Data[0] = 0x04; SPI2_1Wire_Write(CS_LSM6DSL,LSM6DSL_CTRL4_C, Data, 1); Data[0] = 0x00; SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_WHO_AM_I, Data, 1); Data[0] = 0x6A; SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL3_C, Data, 1); Data[0] = 0x4C; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL3_C, Data, 1); SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL3_C, Data, 1); Data[0] = 0x4C; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL3_C, Data, 1); SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_FIFO_CTRL5, Data, 1); Data[0] = 0x00; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_FIFO_CTRL5, Data, 1); SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL2_G, Data, 1); Data[0] = 0x0C; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL2_G, Data, 1); SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL2_G, Data, 1); Data[0] = 0x0C; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL2_G, Data, 1); SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL4_C, Data, 1); Data[0] = 0x04; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL4_C, Data, 1); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : <- \ ACC + / ACC- Side Right - Left + *******************************************************************************/ void LSM6DSL_ACCGyroEnable(void) { uint8_t Data[10], ACCGyroLoop; Data[0] = 0x01; SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL1_XL, Data, 1); Data[0] = 0x40; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL1_XL, Data, 1); Data[0] = 0x0A; SPI2_1Wire_Read(CS_LSM6DSL, LSM6DSL_CTRL2_G, Data, 1); Data[0] = 0x4C; SPI2_1Wire_Write(CS_LSM6DSL, LSM6DSL_CTRL2_G, Data, 1); delay_ms(100); ACCGyroAxis_TypeDef ACCAxis, GyroAxis; LSM6DSL_ACCGyroGet(&gstACCAxis, &gstGyroAxis); for(ACCGyroLoop = 0; ACCGyroLoop < 10; ACCGyroLoop++){ LSM6DSL_ACCGyroGet(&ACCAxis, &GyroAxis); gstACCAxis.ACCGyro_X = (gstACCAxis.ACCGyro_X + ACCAxis.ACCGyro_X)/2; gstACCAxis.ACCGyro_Y = (gstACCAxis.ACCGyro_Y + ACCAxis.ACCGyro_Y)/2; gstACCAxis.ACCGyro_Z = (gstACCAxis.ACCGyro_Z + ACCAxis.ACCGyro_Z)/2; gstGyroAxis.ACCGyro_X = (gstGyroAxis.ACCGyro_X + GyroAxis.ACCGyro_X)/2; gstGyroAxis.ACCGyro_Y = (gstGyroAxis.ACCGyro_Y + GyroAxis.ACCGyro_Y)/2; gstGyroAxis.ACCGyro_Z = (gstGyroAxis.ACCGyro_Z + GyroAxis.ACCGyro_Z)/2; delay_ms(1); } } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LSM6DSL_ACCGyroSetting(void) { uint8_t Data[10]; //ODR 6.6kHz Data[0] = 0x0A; SPI2_1Wire_Read(CS_LSM6DSL, 0x10, Data, 1); Data[0] = 0xA0; SPI2_1Wire_Write(CS_LSM6DSL, 0x10, Data, 1); //FS 4g Data[0] = 0xA0; SPI2_1Wire_Read(CS_LSM6DSL, 0x10, Data, 1); Data[0] = 0xA8; SPI2_1Wire_Write(CS_LSM6DSL, 0x10, Data, 1); //ODR/2 low pass filtered sent to composite filter Data[0] = 0xA8; SPI2_1Wire_Read(CS_LSM6DSL, 0x17, Data, 1); Data[0] &= ~0x80;//LSM6DSL_ACC_GYRO_IN_COMP_MASK; Data[0] |= 0x00;//LSM6DSL_ACC_GYRO_IN_ODR_DIV_2; SPI2_1Wire_Write(CS_LSM6DSL, 0x17, Data, 1); //Enable LPF2 filter in composite filter block Data[0] = 0x60; SPI2_1Wire_Read(CS_LSM6DSL, 0x17, Data, 1); Data[0] &= ~0x80;//LSM6DSL_ACC_GYRO_LPF2_XL_MASK; Data[0] |= 0x80;//LSM6DSL_ACC_GYRO_LPF2_XL_ENABLE; SPI2_1Wire_Write(CS_LSM6DSL, 0x17, Data, 1); //Low pass filter @ ODR/400 Data[0] = 0xE0; SPI2_1Wire_Read(CS_LSM6DSL, 0x17, Data, 1); Data[0] &= ~0x60;//LSM6DSL_ACC_GYRO_HPCF_XL_MASK; Data[0] |= 0x60;//LSM6DSL_ACC_GYRO_HPCF_XL_DIV400; SPI2_1Wire_Write(CS_LSM6DSL, 0x17, Data, 1); //ACC Read Data[0] = 0x00; SPI2_1Wire_Read(CS_LSM6DSL, 0x10, Data, 1); //Set LSB to 0 >> Analog filter 1500Hz Data[0] &= 0xFE; SPI2_1Wire_Write(CS_LSM6DSL, 0x10, Data, 1); // Initialize settings for 6-axis MEMS Gyroscope // FS 2000dps */ // ODR 416Hz */ // LPF1 FTYPE set to 10b Data[0] = 0xA8; SPI2_1Wire_Read(CS_LSM6DSL, 0x15, Data, 1); Data[0] &= ~0x03;//LSM6DSL_ACC_GYRO_FTYPE_MASK Data[0] |= 0x01;//LSM6DSL_ACC_GYRO_LP_G_NARROW SPI2_1Wire_Write(CS_LSM6DSL, 0x15, Data, 1); //Gyroscope settings: full scale 2000dps, ODR 416Hz Data[0] = 0x6C; SPI2_1Wire_Write(CS_LSM6DSL, 0x11, Data, 1); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LSM6DSL_ACCGyro(uint8_t *pRawdata, ACCGyroAxis_TypeDef *ACCGyroAxis, eModeACCGyro_TypeDef chMode) { short int ACCGyroTemp; if(chMode == eModeACC){ ACCGyroTemp = ((((uint16_t)pRawdata[1]) << 8) + (uint16_t)pRawdata[0]); ACCGyroAxis->ACCGyro_X = (ACCGyroTemp * LSM6DSL_ACC_SENSITIVITY); ACCGyroTemp = ((((uint16_t)pRawdata[3]) << 8) + (uint16_t)pRawdata[2]); ACCGyroAxis->ACCGyro_Y = (ACCGyroTemp * LSM6DSL_ACC_SENSITIVITY); ACCGyroTemp = ((((uint16_t)pRawdata[5]) << 8) + (uint16_t)pRawdata[4]); ACCGyroAxis->ACCGyro_Z = (ACCGyroTemp * LSM6DSL_ACC_SENSITIVITY); } else if(chMode == eModeGyro){ ACCGyroTemp = ((((uint16_t)pRawdata[1]) << 8) + (uint16_t)pRawdata[0]); ACCGyroAxis->ACCGyro_X = (ACCGyroTemp * LSM6DSL_GYRO_SENSITIVITY); ACCGyroTemp = ((((uint16_t)pRawdata[3]) << 8) + (uint16_t)pRawdata[2]); ACCGyroAxis->ACCGyro_Y = (ACCGyroTemp * LSM6DSL_GYRO_SENSITIVITY); ACCGyroTemp = ((((uint16_t)pRawdata[5]) << 8) + (uint16_t)pRawdata[4]); ACCGyroAxis->ACCGyro_Z = (ACCGyroTemp * LSM6DSL_GYRO_SENSITIVITY); } } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LSM6DSL_RawData(uint8_t *pAddr, uint8_t *pRawData, uint8_t chLen) { uint8_t SpiLoop; for(SpiLoop = 0; SpiLoop < chLen; SpiLoop++){ // UART1_printf("%02X, %02X, %02X \r\n", CS_LSM6DSL, pAddr[SpiLoop], pRawData[SpiLoop]); SPI2_1Wire_Read(CS_LSM6DSL, pAddr[SpiLoop], &pRawData[SpiLoop], 1 ); } } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LSM6DSL_ACCGyroGet(ACCGyroAxis_TypeDef *ACCAxis, ACCGyroAxis_TypeDef *GyroAxis) { const uint8_t Data_ACCGyro[15] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xFE}; uint8_t Addr_ACCGyro[15] = \ {LSM6DSL_OUTX_L_XL, LSM6DSL_OUTX_H_XL, LSM6DSL_OUTY_L_XL, LSM6DSL_OUTY_H_XL, LSM6DSL_OUTZ_L_XL, LSM6DSL_OUTZ_H_XL\ , LSM6DSL_CTRL1_XL,\ LSM6DSL_OUTX_L_G, LSM6DSL_OUTX_H_G, LSM6DSL_OUTY_L_G, LSM6DSL_OUTY_H_G, LSM6DSL_OUTZ_L_G, LSM6DSL_OUTZ_H_G\ , LSM6DSL_CTRL2_G, LSM6DSL_CTRL2_G}; uint8_t Data[15] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xFE}; uint8_t pData[6]; memcpy(Data, Data_ACCGyro, 15); LSM6DSL_RawData(Addr_ACCGyro, Data, 15);//0~5, 7~12 memcpy(pData, Data, 6); LSM6DSL_ACCGyro(pData, ACCAxis, eModeACC); memcpy(pData, Data+7, 6); LSM6DSL_ACCGyro(pData, GyroAxis, eModeGyro); } /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ typedef struct { int32_t Mag_X; int32_t Mag_Y; int32_t Mag_Z; }MagnetAxis_TypeDef; //#define LIS2MDL_Reserved 00 - 44 Reserved #define LIS2MDL_OFFSET_X_REG_L 0x45 //r/w Hard-iron registers #define LIS2MDL_OFFSET_X_REG_H 0x46 //r/w #define LIS2MDL_OFFSET_Y_REG_L 0x47 //r/w #define LIS2MDL_OFFSET_Y_REG_H 0x48 //r/w #define LIS2MDL_OFFSET_Z_REG_L 0x49 //r/w #define LIS2MDL_OFFSET_Z_REG_H 0x4A //r/w //#define LIS2MDL_RESERVED 4B-4C Reserved #define LIS2MDL_WHO_AM_I 0x4F //r //#define LIS2MDL_RESERVED 50-5F Reserved #define LIS2MDL_CFG_REG_A 0x60 //r/w Configuration #define LIS2MDL_CFG_REG_B 0x61 //r/w #define LIS2MDL_CFG_REG_C 0x62 //r/w #define LIS2MDL_INT_CRTL_REG 0x63 //r/w configuration registers #define LIS2MDL_INT_SOURCE_REG 0x64 //r #define LIS2MDL_INT_THS_L_REG 0x65 //r/w #define LIS2MDL_INT_THS_H_REG 0x66 //r/w #define LIS2MDL_STATUS_REG 0x67 //r #define LIS2MDL_OUTX_L_REG 0x68 //r Output registers #define LIS2MDL_OUTX_H_REG 0x69 //r #define LIS2MDL_OUTY_L_REG 0x6A //r #define LIS2MDL_OUTY_H_REG 0x6B //r #define LIS2MDL_OUTZ_L_REG 0x6C //r #define LIS2MDL_OUTZ_H_REG 0x6D //r #define LIS2MDL_TEMP_OUT_L_REG 0x6E //r Temperature sensor #define LIS2MDL_TEMP_OUT_H_REG 0x6F //r /* Private macro ------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes ------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ extern void UART1_printf(const char *fmt,...); MagnetAxis_TypeDef gStMagnetAxis; /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LIS2MDL_MagnetInit(void) { uint8_t Data[10]; Data[0] = 0x00; SPI2_1Wire_Read(CS_LIS2MDL, LIS2MDL_WHO_AM_I, Data, 1); Data[0] = 0x40; SPI2_1Wire_Read(CS_LIS2MDL, LIS2MDL_CFG_REG_A, Data, 1);//reboot memory content Data[0] = 0x0F; SPI2_1Wire_Write(CS_LIS2MDL, LIS2MDL_CFG_REG_A, Data, 1);//Output data rate configuration - 50Hz SPI2_1Wire_Read(CS_LIS2MDL, LIS2MDL_CFG_REG_C, Data, 1); Data[0] = 0x10; SPI2_1Wire_Write(CS_LIS2MDL, LIS2MDL_CFG_REG_C, Data, 1);// reading of incorrect data is avoided when the user reads asynchronously SPI2_1Wire_Read(CS_LIS2MDL, LIS2MDL_CFG_REG_A, Data, 1); Data[0] = 0x0F; SPI2_1Wire_Write(CS_LIS2MDL, LIS2MDL_CFG_REG_A, Data, 1); SPI2_1Wire_Read(CS_LIS2MDL, LIS2MDL_CFG_REG_C, Data, 1); Data[0] = 0x10; SPI2_1Wire_Write(CS_LIS2MDL, LIS2MDL_CFG_REG_C, Data, 1); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : 1. Write CFG_REG_A = 80h // Enable temperature compensation //Mag = 10 Hz (high-resolution and continuous mode) 2. Write CFG_REG_C = 01h // Mag data-ready interrupt enable *******************************************************************************/ void LIS2MDL_MagnetEnable(void) { uint8_t Data[10]; Data[0] = 0x0A; SPI2_1Wire_Read(CS_LIS2MDL, LIS2MDL_CFG_REG_A, Data, 1); Data[0] = 0x0C; SPI2_1Wire_Write(CS_LIS2MDL, LIS2MDL_CFG_REG_A, Data, 1);//100Hz } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : Initialize settings for Magnetometer settings (By default after reset is in in idle mode) *******************************************************************************/ void LIS2MDL_MagnetSetting(void) { uint8_t Data[10]; Data[0] = 0x8C; SPI2_1Wire_Write(CS_LIS2MDL, LIS2MDL_CFG_REG_A, Data, 1); Data[0] = 0x02; SPI2_1Wire_Write(CS_LIS2MDL, LIS2MDL_CFG_REG_B, Data, 1); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LIS2MDL_Magnet(uint8_t *pRawdata, MagnetAxis_TypeDef *MagnetAxis, float fSensitivity) { short int MagnetTemp; MagnetTemp = (((uint16_t)pRawdata[1]) << 8) + (uint16_t)pRawdata[0]; MagnetAxis->Mag_X = (MagnetTemp * fSensitivity); MagnetTemp = (((uint16_t)pRawdata[3]) << 8) + (uint16_t)pRawdata[2]; MagnetAxis->Mag_Y = (MagnetTemp * fSensitivity); MagnetTemp = (((uint16_t)pRawdata[5]) << 8) + (uint16_t)pRawdata[4]; MagnetAxis->Mag_Z = (MagnetTemp * fSensitivity); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LIS2MDL_RawData(uint8_t *pAddr, uint8_t *pRawData, uint8_t chLen) { uint8_t SpiLoop; for(SpiLoop = 0; SpiLoop < chLen; SpiLoop++){ // UART1_printf("%02X, %02X, %02X \r\n", CS_LIS2MDL, pAddr[SpiLoop], pRawData[SpiLoop]); SPI2_1Wire_Read(CS_LIS2MDL, pAddr[SpiLoop], &pRawData[SpiLoop], 1 ); } } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LIS2MDL_MagnetGet(MagnetAxis_TypeDef *MagnetAxis) { uint8_t Addr_Magnet[6] = {0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D}; uint8_t Data[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; int16_t *pRawData; float Sensitivity = 1.5f; LIS2MDL_RawData(Addr_Magnet, Data, 6); LIS2MDL_Magnet(Data, MagnetAxis, Sensitivity); } /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ //#define LPS22HB_Reserved 0x00 - 0A - Reserved #define LPS22HB_INTERRUPT_CFG 0x0B //r/w Interrupt register #define LPS22HB_THS_P_L 0x0C //r/w threshold registers #define LPS22HB_THS_P_H 0x0D //r/w //#define LPS22HB_Reserved 0E - Reserved #define LPS22HB_WHO_AM_I 0x0F //r Who am I #define LPS22HB_CTRL_REG1 0x10 //r/w #define LPS22HB_CTRL_REG2 0x11 //r/w Control registers #define LPS22HB_CTRL_REG3 0x12 //r/w //#define LPS22HB_Reserved 13 - Reserved #define LPS22HB_FIFO_CTRL 0x14 //r/w FIFO configuration register #define LPS22HB_REF_P_XL 0x15 //r/w #define LPS22HB_REF_P_L 0x16 //r/w Reference pressure registers #define LPS22HB_REF_P_H 0x17 //r/w #define LPS22HB_RPDS_L 0x18 //r/w offset registers #define LPS22HB_RPDS_H 0x19 //r/w #define LPS22HB_RES_CONF 0x1A //r/w Resolution register //#define LPS22HB_Reserved 1B - 24 - Reserved #define LPS22HB_INT_SOURCE 0x25 //r Interrupt register #define LPS22HB_FIFO_STATUS 0x26 //r FIFO status register #define LPS22HB_STATUS 0x27 //r Status register #define LPS22HB_PRESS_OUT_XL 0x28 //r #define LPS22HB_PRESS_OUT_L 0x29 //r Pressure output registers #define LPS22HB_PRESS_OUT_H 0x2A //r #define LPS22HB_TEMP_OUT_L 0x2B //r Temperature output registers #define LPS22HB_TEMP_OUT_H 0x2C //r //#define LPS22HB_Reserved 2D - 32 - Reserved #define LPS22HB_LPFP_RES 0x33 //r Filte0xreset register /* Private macro ------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes ------------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LPS22HB_TempPreInit(void) { uint8_t Data[10]; Data[0] = 0x01; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG2, Data, 1); Data[0] = 0xFC; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG2, Data, 1); Data[0] = 0x01; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); Data[0] = 0x01; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); Data[0] = 0x00; SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_WHO_AM_I, Data, 1); Data[0] = 0xB1; SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_RES_CONF, Data, 1); Data[0] = 0x01; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_RES_CONF, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); Data[0] = 0x01; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); Data[0] = 0x01; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); Data[0] = 0x01; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); Data[0] = 0x03; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG2, Data, 1); Data[0] = 0x00; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG2, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); Data[0] = 0x03; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG2, Data, 1); Data[0] = 0xF8; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG2, Data, 1); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LPS22HB_TempPreEnable(void) { uint8_t Data[10]; Data[0] = 0x0A; SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); Data[0] = 0x33; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); Data[0] = 0x0A; SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); Data[0] = 0x33; SPI2_1Wire_Write(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); SPI2_1Wire_Read(CS_LPS22HB, LPS22HB_CTRL_REG1, Data, 1); } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LPS22HB_Press(uint8_t *pRawdata, float *fPress) { int32_t RawPresse, Pout; uint32_t Temp = 0; uint8_t PressLoop; for(PressLoop = 0; PressLoop < 3; PressLoop++){ Temp |= (((uint32_t)pRawdata[PressLoop]) << (8 * PressLoop)); } /* convert the 2's complement 24 bit to 2's complement 32 bit */ if(Temp & 0x00800000){ Temp |= 0xFF000000; } RawPresse = ((int32_t)Temp); Pout = (RawPresse * 100) / 4096; *fPress = ( float )Pout / 100.0f; } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LPS22HB_Temperature(uint8_t *pRawdata, float *fTemperature) { short int TemperatureTemp = 0, Tout = 0; TemperatureTemp = (((uint16_t)pRawdata[1]) << 8) + (uint16_t)pRawdata[0]; Tout = (TemperatureTemp * 10) / 100; *fTemperature = (float)Tout / 10.0f; } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LPS22HB_RawData(uint8_t *pAddr, uint8_t *pRawData, uint8_t chLen) { uint8_t SpiLoop; for(SpiLoop = 0; SpiLoop < chLen; SpiLoop++){ // UART1_printf("%02X, %02X, %02X \r\n", CS_LPS22HB, pAddr[SpiLoop], pRawData[SpiLoop]); SPI2_1Wire_Read(CS_LPS22HB, pAddr[SpiLoop], &pRawData[SpiLoop], 1 ); } } /******************************************************************************* * Function Name : * Parameters : None * Return : None * Description : *******************************************************************************/ void LPS22HB_TempPressGet(float *fPress, float *ftemperature) { uint8_t Addr_Temperature[2] = {0x2B, 0x2C}; uint8_t Addr_Pressure[3] = {0x28, 0x29, 0x2A}; uint8_t data[3] = {0x4F, 0xFF, 0x00}; LPS22HB_RawData(Addr_Temperature, data, 2); LPS22HB_Temperature(data, ftemperature); LPS22HB_RawData(Addr_Pressure, data, 3); LPS22HB_Press(data, fPress); } /******************************************************************************* * Function Name : * Parameters : None * Return : * Description : *******************************************************************************/ void MeasurementSensorData(const uint8_t ConvertType,ACCGyroAxis_TypeDef *pACCAxis, ACCGyroAxis_TypeDef *pGyroAxis, MagnetAxis_TypeDef *pMagnetAxis, float *pfPress, float *pftemperature, float *pfBatt, uint16_t *pBatt_Percent) { int32_t Tmp; ACCGyroAxis_TypeDef ACCAxis, GyroAxis; MagnetAxis_TypeDef MagnetAxis; float fPress, ftemperature; /* Measurement */ LSM6DSL_ACCGyroGet(&ACCAxis, &GyroAxis); LIS2MDL_MagnetGet(&MagnetAxis); LPS22HB_TempPressGet(pfPress, pftemperature); *pfBatt = Calculation_VBAT(uhADCxConvertedValue[0], 0); *pBatt_Percent = Calculation_VBAT_Percent(*pfBatt, MINVOLTAGE, MAXVOLTAGE, TARGETPERCENT); pMagnetAxis->Mag_X = (int32_t) MagnetAxis.Mag_X; pMagnetAxis->Mag_Y = (int32_t) MagnetAxis.Mag_Y; pMagnetAxis->Mag_Z = (int32_t) MagnetAxis.Mag_Z; if(ConvertType == 1){ Tmp = pACCAxis->ACCGyro_X; pACCAxis->ACCGyro_X = pACCAxis->ACCGyro_Y; pACCAxis->ACCGyro_Y = -Tmp; Tmp = pGyroAxis->ACCGyro_X; pGyroAxis->ACCGyro_X = pGyroAxis->ACCGyro_Y; pGyroAxis->ACCGyro_Y = -Tmp; Tmp = pMagnetAxis->Mag_X; pMagnetAxis->Mag_X = pMagnetAxis->Mag_Y; pMagnetAxis->Mag_Y = -Tmp; } else if (ConvertType == 2){ } else if (ConvertType == 3){ pACCAxis->ACCGyro_X = -ACCAxis.ACCGyro_Y; pACCAxis->ACCGyro_Y = ACCAxis.ACCGyro_X; pACCAxis->ACCGyro_Z = ACCAxis.ACCGyro_Z; pGyroAxis->ACCGyro_X = -GyroAxis.ACCGyro_Y; pGyroAxis->ACCGyro_Y = GyroAxis.ACCGyro_X; pGyroAxis->ACCGyro_Z = GyroAxis.ACCGyro_Z; pMagnetAxis->Mag_X = -MagnetAxis.Mag_Y; pMagnetAxis->Mag_Y = MagnetAxis.Mag_X; } else if (ConvertType == 4){ pACCAxis->ACCGyro_X = -ACCAxis.ACCGyro_X; pACCAxis->ACCGyro_Y = -ACCAxis.ACCGyro_Y; pGyroAxis->ACCGyro_X = -GyroAxis.ACCGyro_X; pGyroAxis->ACCGyro_Y = -GyroAxis.ACCGyro_Y; pMagnetAxis->Mag_X = -MagnetAxis.Mag_X; pMagnetAxis->Mag_Y = -MagnetAxis.Mag_Y; } else if (ConvertType == 5){ pACCAxis->ACCGyro_X = ACCAxis.ACCGyro_X; pACCAxis->ACCGyro_Y = ACCAxis.ACCGyro_Y; pACCAxis->ACCGyro_Z = ACCAxis.ACCGyro_Z; pGyroAxis->ACCGyro_X = GyroAxis.ACCGyro_X; pGyroAxis->ACCGyro_Y = GyroAxis.ACCGyro_Y; pGyroAxis->ACCGyro_Z = GyroAxis.ACCGyro_Z; } } |
from: https://eroro.tistory.com/497
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
uint32_t timers = 0; TIM_HandleTypeDef TimHandle; void main(void) { HAL_Init(); /* Configure the system clock to 48 MHz */ SystemClock_Config(); /* Compute the prescaler value to have TIMx counter clock equal to 10000 Hz */ uwPrescalerValue = (uint32_t)(SystemCoreClock / 1000000) - 1;//48000000 UART1_printf("SystemCoreClock : %d, uwPrescalerValue %d\r\n", SystemCoreClock, uwPrescalerValue); /* Set TIMx instance */ TimHandle.Instance = TIMx; /* Initialize TIMx peripheral as follows: + Period = 10000 - 1 + Prescaler = (SystemCoreClock/10000) - 1 + ClockDivision = 0 + Counter direction = Up */ // about 1000000 = 1s, 100000 = 0.1s, 10000 = 0.01s, 1000 = 0.001s, // 100 = 0.0001s, 10 = 0.00001s, 1 = 0.000001s TimHandle.Init.Period = 2000000; TimHandle.Init.Prescaler = uwPrescalerValue; TimHandle.Init.ClockDivision = 0; TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; TimHandle.Init.RepetitionCounter = 0; if (HAL_TIM_Base_Init(&TimHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } __HAL_TIM_SetCounter(&TimHandle, 0); HAL_TIM_Base_Start(&TimHandle); uint32_t beforetime=0; while(1){ if(__HAL_TIM_GetCounter(&TimHandle) >= 1000000){ __HAL_TIM_SetCounter(&TimHandle, 0); UART1_printf("%d, ", timers); timers++; } } } |
from: https://eroro.tistory.com/488 https://github.com/blalor/avr-softuart 위 사이트에 나와있는 소스코드를 STM32F103에서 동작하도록 변경 9600bps에 맞췄습니다만 본인이 사용하는 클럭 설정이나 다른 코어라면 코어의 처리 속도등을 고려해서 Timer의 발생 시간을 조절해주어야 합니다. 계산해보면 1/9600 = […]
from: https://eroro.tistory.com/471 Buzzer Melody 예제입니다. 멜로디를 위한 테스트 예제로 참고만 하면 될 것 같습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
void TIM2_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; NVIC_InitTypeDef NVIC_InitStructure; /* TIM2 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); /* Time base configuration */ // Overflow Interrupt On 10 usec 타이머주기 TIM_TimeBaseStructure.TIM_Period = 10; // Timer/Count2 Clock = 36Mhz / (35 + 1) = 1Mhz = 1 usec TIM_TimeBaseStructure.TIM_Prescaler = 35; TIM_TimeBaseStructure.TIM_ClockDivision = 0; // 카운터모드동작 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* TIM2 counter enable */ TIM_Cmd(TIM2, ENABLE); /* TIM IT enable */ TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); /* Enable the TIM2 gloabal Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } /* unut : sec 도 0.030578 0.015289 0.007645 0.003822 0.001911 0.000956 0.000478 C# 0.028862 0.014431 0.007215 0.003608 0.001804 0.000902 0.000451 레 0.027242 0.013621 0.006810 0.003405 0.001703 0.000851 0.000426 D# 0.025713 0.012856 0.006428 0.003214 0.001607 0.000804 0.000402 미 0.024270 0.012135 0.006067 0.003034 0.001517 0.000758 0.000379 파 0.022908 0.011454 0.005727 0.002863 0.001432 0.000716 0.000358 F# 0.021622 0.010811 0.005405 0.002703 0.001351 0.000676 0.000338 솔 0.020408 0.010204 0.005102 0.002551 0.001276 0.000638 0.000319 G# 0.019263 0.009631 0.004816 0.002408 0.001204 0.000602 0.000301 라 0.018182 0.009091 0.004545 0.002273 0.001136 0.000568 0.000284 A# 0.017161 0.008581 0.004290 0.002145 0.001073 0.000536 0.000268 시 0.016198 0.008099 0.004050 0.002025 0.001012 0.000506 0.000253 0.000033 0.000065 0.000131 0.000262 0.000523 0.001047 0.002093 0.000035 0.000069 0.000139 0.000277 0.000554 0.001109 0.002217 0.000037 0.000073 0.000147 0.000294 0.000587 0.001175 0.002349 0.000039 0.000078 0.000156 0.000311 0.000622 0.001245 0.002489 0.000041 0.000082 0.000165 0.000330 0.000659 0.001319 0.002637 0.000044 0.000087 0.000175 0.000349 0.000698 0.001397 0.002794 0.000046 0.000092 0.000185 0.000370 0.000740 0.001480 0.002960 0.000049 0.000098 0.000196 0.000392 0.000784 0.001568 0.003136 0.000052 0.000104 0.000208 0.000415 0.000831 0.001661 0.003322 0.000055 0.000110 0.000220 0.000440 0.000880 0.001760 0.003520 0.000058 0.000117 0.000233 0.000466 0.000932 0.001865 0.003729 0.000062 0.000123 0.000247 0.000494 0.000988 0.001976 0.003951 */ #define MUSIC_REST 0 #define MUSIC_DO 191 #define MUSIC_C_SHARP 180 #define MUSIC_RE 170 #define MUSIC_D_SHARP 161 #define MUSIC_MI 152 #define MUSIC_PA 143 #define MUSIC_F_SHARP 135 #define MUSIC_SOL 128 #define MUSIC_G_SHARP 120 #define MUSIC_RA 114 #define MUSIC_A_SHARP 107 #define MUSIC_SI 101 #define MUSIC_HDO 96 uint32_t Sound = 0; uint32_t Music = 0; int main(void) { GPIO_InitTypeDef GPIO_InitStructure; /* System Clocks Configuration */ RCC_Configuration(); /* Enable the GPIO BUZZER Clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* Configure the GPIO BUZZER pin */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); TIM2_Configuration(); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_REST; Delay_Us(10000); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_RA; Delay_Us(100000); Music = MUSIC_REST; Delay_Us(10000); Music = MUSIC_RA; Delay_Us(100000); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_REST; Delay_Us(10000); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_MI; Delay_Us(100000); Delay_Us(100000); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_REST; Delay_Us(10000); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_MI; Delay_Us(100000); Music = MUSIC_REST; Delay_Us(10000); Music = MUSIC_MI; Delay_Us(100000); Music = MUSIC_RE; Delay_Us(100000); Delay_Us(100000); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_REST; Delay_Us(10000); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_RA; Delay_Us(100000); Music = MUSIC_REST; Delay_Us(10000); Music = MUSIC_RA; Delay_Us(100000); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_REST; Delay_Us(10000); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_MI; Delay_Us(100000); Delay_Us(100000); Music = MUSIC_SOL; Delay_Us(100000); Music = MUSIC_MI; Delay_Us(100000); Music = MUSIC_RE; Delay_Us(100000); Music = MUSIC_MI; Delay_Us(100000); Music = MUSIC_DO; Delay_Us(100000); Delay_Us(100000); TIM_Cmd(TIM2, DISABLE); GPIOB->BRR = GPIO_Pin_0; } stm32f10x_it.c extern uint32_t Sound; extern uint32_t Music; /** * @brief This function handles TIM2 global interrupt request. * @param None * @retval None */ void TIM2_IRQHandler(void) // 1mS Timer { if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_Update); Sound++; if(Sound >= Music){ GPIOB->ODR ^= GPIO_Pin_0; Sound = 0; } } } |
from: https://eroro.tistory.com/430
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/*!< Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST */ #define GPIO_Remap_SWJ_NoJTRST ((uint32_t)0x00300100) /*!< JTAG-DP Disabled and SW-DP Enabled */ #define GPIO_Remap_SWJ_JTAGDisable ((uint32_t)0x00300200) /*!< Full SWJ Disabled (JTAG-DP + SW-DP) */ #define GPIO_Remap_SWJ_Disable ((uint32_t)0x00300400) /* Enable the AFIO Clock for Remap */ RCC_APB2PeriphClockCmd (RCC_APB2Periph_AFIO, ENABLE); /* Jtag Pin Disable */ GPIO_PinRemapConfig (GPIO_Remap_SWJ_JTAGDisable, ENABLE); |
c2960l-universalk9-tar.152-7.E8
U17_3.02_07_18_2022.signed
from: https://www.2cpu.co.kr/PDS/14823 24.21.0-0159_SAS_MR_FW_IMAGE_APP_4.680.00-8577
from: https://www.2cpu.co.kr/PDS/14824 16.00.12.00 IT mode SAS3_FW_Phase16.0-16.00.12.00_Firmware
MeshCommander
c1240-k9w7-tar.124-25d.JA c1240-k9w7-tar.124-21a.JY c1240-k9w7-tar.124-21a.JA1
v3.2.11 FusionIOdrive2
fusion_3.2.16-20180821.fff
from: https://rhye.org/post/stm32-with-opencm3-2-spi-and-dma/ 이전 섹션 에서는 대체 기능을 다루고 UART를 통해 로그 콘솔을 구성했습니다. 이번에는 에서 사용할 수 있는 SPI 주변 장치를 살펴보고 STM32F0이를 사용하여 데이터를 일부 시프트 레지스터로 빠르게 이동한 다음 DMA를 사용하여 주 […]
출처: https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=golsm21&logNo=120141464685 SPI 1). 개요 (1). SPI는 일반적으로 외부 디바이스와 4핀으로 연결됨. ①. MISO – Master In / Slave Out data. – Master 모드에서는 입력, Slave 모드에서는 출력 신호로 사용됨. […]
from: https://deepbluembedded.com/stm32-gpio-leds-buttons-interfacing-driver/ Back again to resume those STM32 tutorials. In this tutorial, we’ll be discussing the usage of STM32 GPIO pins to drive LEDs and read the digital state […]
from: https://deepbluembedded.com/stm32-joystick-library-driver-examples/ In this tutorial, we’ll be discussing the usage of STM32 ADC and analog input pins to interface and read one joystick or more. I’ll also show you […]
from: https://deepbluembedded.com/stm32-keypad-interfacing-library/ STM32 KeyPad Interfacing Driver (Library) In this tutorial, we’ll be discussing the usage of STM32 GPIO pins to interface and read a keypad matrix, It can be […]
from: https://deepbluembedded.com/stm32-timer-encoder-mode-stm32-rotary-encoder-interfacing/ STM32 Timer Encoder Mode – STM32 Rotary Encoder Interfacing In this tutorial, we’ll discuss the STM32 Timer encoder mode. We’ll also do STM32 rotary encoder interfacing using […]
https://hackaday.io/page/12671-how-to-debug-w806-and-w801-mcus 참조: https://github.com/IOsetting/wm-sdk-w806 WinnerMicro W801 https://hackaday.io/page/11837-getting-started-with-w806-240mhz-32-bit-mcu W806 is quite an interesting product in terms of price and performance. One of the biggest drawbacks of this platform is lack of popular […]
STM32F103 Core: ARM® 32-bit Cortex®-M3 CPU 72 MHz maximum frequency, 1.25 DMIPS/MHz (Dhrystone 2.1) performance at 0 wait state memory access Single-cycle multiplication and hardware division Memories 256 to 512 […]
https://openwrt.org/toh/tp-link/archer_c7 The TP-Link Archer C7 AC1750 is a wireless router with both 2.4 GHz and 5 GHz radios. It has five 1 gigabit/second Ethernet ports, and a moderately fast processor. Available since 201x. Hardware […]
출처: OpenWRT 공유기로 WiFi extender/Repeater/Bridge 만들기 이것은 OpenWRT 유무선 공유기를 가지고, 기존에 존재하는 무선네트워크를 확장해서 유선으로 연결 가능한 원격 네트워크를 만드는 방법이다. https://openwrt.org/docs/guide-user/network/wifi/relay_configuration 의 번역판이라고 보면 된다. 그림에서 보이는 바와 […]
출처: https://hook.tistory.com/entry/OpenWRT-펌웨어-공유기로-Dump-AP또는-bridged-AP-만드는-방법 이미 유·무선공유기가 존재하는 환경에서 특정한 이유로 무선 접속 반경을 넓혀야만 하는 경우가 종종 발생한다. ※ 대표적으로 아파트에서 거실에 있는 유·무선공유기의 무선신호가 화장실등에 특정지역에서 너무 속도가 안나오는 상황! […]
https://www.prolific.com.tw/US/ShowProduct.aspx?p_id=225&pcid=41 PL2303_v408_2022-07-28 Windows Driver Installer Setup Program ( Win7 / Win8.1 / Win10 / Win11) Installer version & Build date: 4.0.8 (2022-07-28) Windows 11 ( 64-bit ) WDF WHQL Driver: v3.9.3.0 (05/30/2022) / […]
https://blog.zakkemble.net/avrdudess-a-gui-for-avrdude/ Some key features: Supports all programmers and MCUs that AVRDUDE supports Supports presets, allowing you to change between devices and configurations quickly and easily Drag and drop files for […]
출처: http://choavrweb.blogspot.com/p/atmega2560-io-port.html ATmega2560 I/O Port 개요 10개의 8비트 양방향 병렬 I/O 포트(PORTA~F,H,J,K,L) 1개의6비트 양방향 병렬 I/O 포트(PORTG) 각 PORT별 3개 I/O 레지스터:Data Rgister, Data Direction Register, Input Pins Register DDR(Data […]
출처: https://robodream.tistory.com/39 기본적인 포트에 값입력법 그리고 포트설정에 대해서 알아 보겠습니다. 제일 먼저 소개할 함수는 해당 포트에 대해 입출력을 미리 설정해주는 함수인 PinMode()입니다. 이 함수는 pinMode(포트번호 , 입/출력); 구조로 […]
http://zone94.com/downloads/software/operating-systems/123-windows-xp-professional-sp3-x86-integral-edition magnet 한글화는 다음 사이트의 내용을 참고하세요. https://codingcoding.tistory.com/891 [———- CHANGELOG ———-] (#) 2023.6.16 Changes: * Added a few cosmetic improvements. * Added Outlook Express 6 – Standalone Installer v1.0.2. […]
Features AC input High isolation voltage between input and output (V : 5 000Vrms ) Compact dual-in-line package PC814 (1-channel type ) PC824 (2-channel type ) PC844 (4-channel type ) Current […]
eleparts DOWO NUP2105L / SOT-23 ESD Protection Devices ROHS, 포장단위:10ea
eleparts CRYSTAL 32.7680KHZ 7PF SMD, 32.768 kHz ±20ppm 수정 7pF 4-SOJ, 5.5mm 피치 주파수: 32.768kHz 부하 정전 용량: 7pF 동작온도: -40°C ~ 85°C 실장 유형: 표면실장(SMD, SMT) 패키지/케이스: 4-SOJ, 5.50mm […]
출처: https://louie0724.tistory.com/361 1. 기본적인 스위치 구성 회로 – 위의 콘덴서가 없을 경우 아래와 같이 노이즈가 발생하게 됨 2. GPIO 외부 인터럽트 설정 – NVIC에서 외부 인터럽트를 활성화 […]
출처: https://louie0724.tistory.com/359 1. Timer 기본 설정 – 설정 전에 기존의 HCLK 값이 100MHz 임을 확인함 – TIM7 활성화함 – Prescaler와 Auto-Reload 값을 변경함 ※ 강의 예제 Auto Reload Register = Period HCLK = 168MHZ […]
출처: https://louie0724.tistory.com/362 1. ADC와 DMA 설명 1) ADC(Analog to Digital Converter) 계산방법 – STM32는 Reference 전압이 3.3v 임 – ADC 1당 전압[V[ = VREF(Voltage Reference) / Bit Resolution = 3.3v […]
출처: https://jeonhj.tistory.com/46 MCU에서 인터럽트 핸들러 안에서는 동작을 최대한 짧게 가져가야 합니다. 그래서 USART와 같은 통신 인터페이스를 사용할때에는 Queue Buffer 구조를 사용합니다. 큐(Queue)는 FIFO(First-In, First-Out)로 가장 먼저 들어온 데이터가 가장 먼저 […]
출처: https://blog.naver.com/cubloc MAXIM에서 괜찮은 칩이 나왔군요. RTD센서 (보통 PT100옴이라고 불리죠)를 연결해서 MCU와 직접 연결할 수 있도록 SPI 프로토콜로 바꿔주는 칩입니다. RTD센서는 변화량이 100옴밖에 안되기 때문에, MCU에 직접 물릴 수 는 […]
출처: https://blog.naver.com/cubloc/220100023298 전원분리를 아이솔레이션 (isolation)이라고 부릅니다. 옵토커플러만 사용하면 전원분리가 된다고 생각하시는 분들이 있습니다. 아이솔레이션은 아래 회로처럼 전원, 입력회로, 출력회로가 모두 분리가 되어서, 마치 섬처럼 5V쪽이 완전 분리되어야 합니다. […]
출처: https://blog.naver.com/cubloc/221079049004 1. 배선길이는 짧을 수록 좋습니다. 배선의 길이가 길수록 L값이 높아지고, 이로인해 임피던스도 높아집니다. 저주파 신호는 상관없지만, 고속신호의 경우 노이즈에 취약해집니다. 그래서 배선길이는 짧을 수록 좋습니다. 2. 파워배선은 두껍게.. […]
PILKOR, 필름콘덴서, 박스타입, PCRC, 32104 104M P-17.5 L (PIN SIZE : 25mm), AC250V 120R, ±20%(tol nparts 스파크 킬러 용량계산법 및 surge에 대해서 (출처:전자및기계장비블로그)
출처: https://blog.naver.com/cubloc/222483728631 갑자기 PC가 멈추는 현장이 있다는 전화를 받았습니다. 서지 공격이 의심된다고하니, 서지 (Surge)가 무엇인지 잘 모르고 계셨습니다. 서지(Surge)란 낙뢰,번개등과 같은 갑작스러운 과전압이 전원계통에 유입되는 자연현상입니다. 서지가 PC나 PLC, […]
출처: https://blog.naver.com/cubloc/222758986782 앞서 RS232C 통신 포트에서 사용할 수 있는 TVS 다이오드에 대해서 알아봤는데요. 다시 정리해보면, RS232C는 +/- 15V 정도의 전압을 취급하고 있으므로 15V 양방향 TVS다이오드를 사용해야 된다고 말씀 드렸습니다. […]
출처: https://blog.naver.com/cubloc/222934043532 신호에 노이즈 나 써지가 섞여들어와서 자꾸 이상동작을 하게 된다고 호소하시는 분들이 있습니다. 신호에 섞인 노이즈 / 써지는 메인 장치에 치명적인 데미지를 주어 최악의 경우 장치를 망가지게 할 수도 […]
출처: https://blog.naver.com/cubloc/221519727821 바이패스 콘덴서( 혹은 디커플링 콘덴서라고도 부름)의 역할은 무엇일까요? 우리가 PCB를 설계할때, 칩 전원단에 콘덴서 0.01uF ~ 0.1uF 정도를 배치하라고 선배들로부터 듣고 그렇게 해왔는데, 왜 이렇게 바이패스 콘덴서를 […]
출처: https://m.blog.naver.com/cubloc/220100115331 제가 자주 사용하는 TVS다이오드 RClamp0502B를 소개합니다. 일반적인 TVS다이오드보다 정전용량이 적어서 고속 데이터 통신선로에 적합합니다. 한 펙케지에 2개가 들어가 있습니다. USB2.0 접속, HDMI 접속 코넥터에 사용하실 수 있습니다. 그림처럼 […]
출처: https://m.blog.naver.com/cubloc/220107182737 I2C 통신을 사용해서 16개의 I/O를 확장할 수 있는 칩입니다. [PCF8575 데이터 시트] 입력으로 사용하기 위해서는 각 I/O를 HIGH상태로 만들어야 하는데, 파워온시 최초상태가 HIGH 상태이므로, 만약 입력모드로만 사용하실 […]
출처: https://m.blog.naver.com/cubloc/220121191648 출력포트가 무지막지하게 많이 필요한 어플리케이션이라면 어찌 하시겠습니까? I/O가 많은 MCU는 가격도 비싼 편입니다. 단순하게 출력포트만 더 필요하다면 시프트 레지스터 74HC595 를 기억해 두십시오. MCU와 단 3가닥으로 […]
출처: https://m.blog.naver.com/cubloc/220142974670 CAN통신이나 RS232, RS485, I2C 회로 등을 설계할때, 아이솔레이터를 사용하면, 외부 노이즈/서지로부터 메인기판을 보호할 수 있습니다. 적당한 디지털 아이솔레이터 칩을 소개합니다. 아날로그 디바이스사의 ADUM1301 이라는 칩입니다. LED와 […]
출처: https://m.blog.naver.com/cubloc/220143152142 RS232, RS485, CAN등을 아이솔레이션 하는 회로를 구성할때 꼭 필요한게 바로, DC/DC 컨버터입니다. 신호를 아이솔레이션 했다면, 반드시 파워도 아이솔레이션 해주어야 하기 때문이죠. 그래서 일반적으로 선택하는게 아래 처럼 생긴 DC/DC […]
출처: https://m.blog.naver.com/cubloc/220143158648 ADC를 신호입력단에서 아이솔레이션 시키는 것은 매우 어려운 일입니다. A/D량을 포토 커플러의 빛의 양으로 바꾸어서 포토TR로 받아내야 하니까요. 그래서 뒷단에 있는 I2C통신 또는 SPI통신을 아이솔레이션 하는 방법을 많이 사용합니다. […]
https://ko.aliexpress.com/item/1005003585993852.html 소개 TP4056 은 정전류/정전압 선형 충전기가 장착 된 완전한 단일 셀 리튬 이온 배터리입니다. TP4056 하단에 방열판이 있고 외부 부품 수가 적은 SOP40 패키지는 TP4056 을 휴대용 응용 […]
https://ko.aliexpress.com/item/1005001280864337.html eleparts 1. 초광각 입력 (4:1), 출력 30W 2. 변환 효율: 91% (Typ) 3. 고립 전압: 1500Vdc 4. 초저 대기 전력 소비: 0.036W (일반) 5. 초고속 시작: 1mS […]
https://ko.aliexpress.com/item/4001049113609.html https://ko.aliexpress.com/item/4001084805134.html (6,309 ~ 7,225)
출처: https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=simonsayz&logNo=220724527073 ESP8266 – The Wrong Solution or Good… 요즘 많이 사용하는 ESP8266을 고속 통신이 필요해서 테스트를 해보았습니다. 인터넷 상에서, 너무 좋은 정보들이 많이 있기는 한데, 개인적으로 정말 필요했던, ESP8266 […]
https://istarik.ru/blog/stm32/148.html 이 노트는 stm32 마이크로컨트롤러를 사용할 때 버튼의 “바운스”를 제거하기 위한 몇 가지 옵션을 설명합니다. 우리는 버튼 또는 기타 저속 접점에 대해 이야기하고 있습니다. 일부 모터의 속도 측정과 같은 빈번한 […]
https://istarik.ru/blog/stm32/149.html ILI9341 드라이버 기반 디스플레이를 SPI 버스를 통해 stm32 마이크로컨트롤러에 연결합니다. 항상 그렇듯이 BluePill 보드에 대한 예가 만들어졌습니다. F3 시리즈 의 스톤을 가지고 계신 분들을 위한 주의사항 . 프로젝트 폴더에는 For_STM32F3 폴더가 있으며 여기 에는 하나의 파일이 […]
https://istarik.ru/blog/stm32/151.html ring buffer: 물론 링은 없으며 수신 버퍼에 대한 일부 배열을 할당하기만 합니다. 이 경우에 6바이트 배열을 할당했다고 가정합니다.나 자신이 그림을 그리기에는 너무 게을러서 인터넷에서 적합한 것을 찾았습니다 … back […]
https://istarik.ru/blog/stm32/144.html stm32에서 Wiegand와 함께 작업하기 위한 라이브러리. 나는 액세스 패널에 손을 댔고, DAHUA DHI-ASR1101A-D라는 이름의 카드 리더기 (그림) 이기도 합니다 . 같은 것도 있지만 버튼이 없고 카드리더기(DHI-ASR1100A-D)만 있고 그외 제조사도 별거 다 있습니다. 이러한 […]
출처: https://rs29.tistory.com/27 Nocuta NF-A8 5V PWM – 보드 : P-NUCLEO-WB55 – 개발 툴 : STM32CubeMX, True Studio – 팬 : 녹투아 NF-A8 5V PWM – 팬 작동 전압 : […]
출처: https://rs29.tistory.com/22 사용한 ST7735 드라이버 탑재 80×160 0.96인치 LCD (사용한 LCD 모듈 기준) – 디스플레이 해상도 : 80×160 (드라이버 지원 해상도는 132×162, 128×160) – 통신 : SPI (사용 모듈의 […]
출처: https://rs29.tistory.com/13 통신 방법 : SPI (최대속도 : 10Mhz) 작동 전압 : 4.0~5.5 환경 : P-NUCLEO-WB55 개발 보드, Atollic TrueSTUDIO [동작] 16 비트 데이터 포맷 사용 (D15~D12 […]
This application note contains explanation with examples for 2 distinct topics: Data reception with UART and DMA when application does not know size of bytes to receive in advance Data […]
https://github.com/liyanboy74/soft-uart soft-uart-master Multi Software Serial (UART) For STM32 The library work fine for virtualize 6 UART full duplex in baud rate 9600. All UART work together parallelly! Library Dir: Softuart.h […]
출처: vuzwa.tistory.com 우선 STM32 MCU의 전원 관련 핀을 살펴보자. 본 포스팅에서는 STM32H723ZGT6 MCU를 이용해서 전원 관련 회로를 확인해보도록 하겠다. Nucleo 보드회로를 살펴보면, 전원 관련핀이 엄청 많다. 우선 각 핀들이 […]