diff --git a/examples/SI4844_STM32_POC/SI4844_STM32_POC.ino b/examples/SI4844_STM32_POC/SI4844_STM32_POC.ino new file mode 100755 index 0000000..d07c475 --- /dev/null +++ b/examples/SI4844_STM32_POC/SI4844_STM32_POC.ino @@ -0,0 +1,176 @@ +/* +* + * SI4844 and STM32F1 connections + * + * | SI4844 pin | STM32F1 pin | Description | + * | --------- | ------------ | ------------------------------------------------- | + * | 2 | PA11 | Interrupt pin | + * | 15 | PA12 | Regurlar digital pin used to RESET control | + * | 16 | PB7 (SDA) | I2C bus (Data) | + * | 17 | PB6 (SCL) | I2C bus (Clocl) | + * + * + * By Ricardo Lima Caratti, 2024. +*/ + +#include + +#define RESET_PIN PA12 +#define INTERRUPT_PIN PA11 +#define DEFAULT_BAND 1 + +SI4844 rx; + +void setup() { + Serial.begin(9600); + delay(1000); + + Serial.print(F("\nESP32C3 - Begin...\n")); + Serial.flush(); + + + instructions(); + // Some crystal oscillators may need more time to stabilize. Uncomment the following line if you are experiencing issues starting the receiver. + // rx.setCrystalOscillatorStabilizationWaitTime(1); + rx.setup(RESET_PIN, INTERRUPT_PIN, DEFAULT_BAND); + showStatus(); + delay(200); + rx.setVolume(48); + showStatus(); +} + + +// Shows instruções +void instructions() { + Serial.println(F("-------------------ESP32C3---CONTROLLER------------------")); + Serial.println(F("Type F - FM; A - AM; 1 to 7 - SW1 to SW7")); + Serial.println(F("Type f - Custom FM - from 77 to 109 MHz - Step 200kHz")); + Serial.println(F("Type h - Custom FM - from 101 to 104 MHz - Step 200kHz")); + Serial.println(F("Type + or - to sound volume")); + Serial.println(F("Type B to Bass; T to Treeble and N to Normal")); + Serial.println(F("Type c - custom band 5.7 to 6.2 MHz")); + Serial.println(F("Type C - CB (custom Band 27.0 to 27.5 MHz")); + Serial.println(F("Type o to Power Down")); + Serial.println(F("Type I to Firmware Information")); + Serial.println(F("---------------------------------------------------")); + delay(500); +} + +// Shows firmware information +void show_firmware_information() { + Serial.println(F("\nSI4844 - Firmware information\n")); + rx.getFirmware(); + Serial.print(F("Final 2 digits of Part Number..: ")); + Serial.println(rx.getFirmwarePartNumber(), HEX); + Serial.print(F("Firmware Major Revision........: ")); + Serial.println(rx.getFirmwareMajorRevision()); + Serial.print(F("Firmware Minor Revision........: ")); + Serial.println(rx.getFirmwareMinorRevision()); + Serial.print(F("Component Major Revision.......: ")); + Serial.println(rx.getFirmwareComponentMajorRevision()); + Serial.print(F("Component Minor Revision.......: ")); + Serial.println(rx.getFirmwareComponentMinorRevision()); + Serial.print(F("Chip Revision..................: ")); + Serial.println(rx.getFirmwareChipRevision()); + Serial.println(F("*****************************")); +} + + +void showStatus() { + Serial.print(F("Band Index: ")); + Serial.print(rx.getStatusBandIndex()); + Serial.print(F(" - ")); + Serial.print(rx.getBandMode()); + Serial.print(F(" - Frequency: ")); + Serial.print(rx.getFrequency(),0); + Serial.print(F(" KHz")); + if (rx.getStatusBandMode() == 0) { + Serial.print(F(" - Stereo ")); + Serial.print(rx.getStereoIndicator()); + } + Serial.print(F(" - Volume: ")); + Serial.print(rx.getVolume()); + Serial.println(""); +} + +// Control +void loop() { + // Read from keyboar (Arduino Serial Monitor) + // Band switch and sound volume control + // It can be replaced by your keyboar, encoder or push button device. + if (Serial.available() > 0) + { + char key = Serial.read(); + switch (key) + { + case 'F': + rx.setBand(1); // FM band + break; + case 'f': + Serial.println(F("Custom FM Band: from to 77 to 109 MHz - Step 200 kHz")); + rx.setCustomBand(3,7700,10900,20); + break; + case 'h': + Serial.println(F("Custom FM Band: from to 101 to 104 MHz - Step 200 kHz")); + rx.setCustomBand(3,10100,10400,20); + break; + case 'a': + case 'A': + rx.setBand(20); // AM band + break; + case '1': + rx.setBand(28); // SW1 band + break; + case '2': + rx.setBand(29); // SW2 band + break; + case '3': + rx.setBand(31); // SW3 band + break; + case '4': + rx.setBand(33); // SW4 band + break; + case '5': + rx.setBand(35); // SW5 band + break; + case '6': + rx.setBand(37); // SW6 band + break; + case '7': + rx.setBand(39); // SW7 band + break; + case '+': // sound volume control + rx.volumeUp(); + break; + case '-': + rx.volumeDown(); + break; + case 'o': + Serial.println(F("Power Down")); + delay(500); + rx.powerDown(); + break; + case 'c': + // Configure the Pre-defined Band (band index 26) to work between 5.7 to 6.2 MHz + // See Si48XX ATDD PROGRAMMING GUIDE, pages 17,18,19 and 20. + Serial.println(F("Custom Band: 5.7 to 6.2 MHz")); + rx.setCustomBand(26,5700,6200,5); + break; + case 'C': + // Configure the Pre-defined Band (band index 40) to work between 27.0 to 27.5 MHz + // See Si48XX ATDD PROGRAMMING GUIDE, pages 17,18,19 and 20. + Serial.println(F("Custom Band: 27.0 to 27.5 MHz")); + rx.setCustomBand(40,27000,27500,5); + break; + case 'I': + case 'i': + show_firmware_information(); + break; + } + } + if (rx.hasStatusChanged()) + { + showStatus(); + } +} + diff --git a/examples/compile_all.sh b/examples/compile_all.sh index 5aba67c..5c66e51 100755 --- a/examples/compile_all.sh +++ b/examples/compile_all.sh @@ -23,13 +23,9 @@ arduino-cli compile -b arduino:avr:nano ./TEST/SI4844_BASS_TREBLE --output-dir ~ arduino-cli compile -b arduino:avr:nano ./TEST/SI4844_CUSTOM_BAND --output-dir ~/Downloads/hex/atmega/SI4844_CUSTOM_BAND arduino-cli compile -b arduino:avr:nano ./TEST/SI4844_FIRMWARE --output-dir ~/Downloads/hex/atmega/SI4844_FIRMWARE - - - echo "********************" echo "Arduino LGT8FX based board" echo "********************" - arduino-cli compile -b lgt8fx:avr:328 ./SI4844_00_MINIMAL --output-dir ~/Downloads/hex/ltg/SI4844_00_MINIMAL arduino-cli compile -b lgt8fx:avr:328 ./SI4844_00_POC --output-dir ~/Downloads/hex/ltg/SI4844_00_POC arduino-cli compile -b lgt8fx:avr:328 ./SI4844_01_OLED --output-dir ~/Downloads/hex/ltg/SI4844_01_OLED @@ -38,18 +34,17 @@ arduino-cli compile -b lgt8fx:avr:328 ./TEST/SI4844_BASS_TREBLE --output-dir ~/D arduino-cli compile -b lgt8fx:avr:328 ./TEST/SI4844_CUSTOM_BAND --output-dir ~/Downloads/hex/ltg/SI4844_CUSTOM_BAND arduino-cli compile -b lgt8fx:avr:328 ./TEST/SI4844_FIRMWARE --output-dir ~/Downloads/hex/ltg/SI4844_FIRMWARE - - echo "********************" echo "ESP32" echo "********************" - arduino-cli compile --fqbn esp32:esp32:esp32-poe-iso ./SI4844_ESP32_POC --output-dir ~/Downloads/hex/esp32/SI4844_ESP32_POC - - echo "********************" echo "ESP8266" echo "********************" - arduino-cli compile --fqbn esp8266:esp8266:generic ./SI4844_ESP8266_POC --output-dir ~/Downloads/hex/esp8266/SI4844_ESP8266_POC + +echo "********************" +echo "STM32" +echo "********************" +arduino-cli compile --fqbn STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 ./SI4844_STM32_POC --output-dir ~/Downloads/hex/STM32/SI4844_STM32_POC \ No newline at end of file