View previous topic :: View next topic |
Author |
Message |
Al in Michigan
Joined: 29 Dec 2024 Posts: 13 Location: michigan
|
|
Posted: Thu Jan 02, 2025 4:42 pm |
|
|
apologies for the formatting that got lost. |
|
|
Al in Michigan
Joined: 29 Dec 2024 Posts: 13 Location: michigan
|
|
Posted: Thu Jan 02, 2025 7:33 pm |
|
|
A more readable version submitted for a sanity check by anyone that is familiar with both libraries.
////////////////////////WRITE////
void qn8007_write(int Reg, int val)
{
i2c_start();
i2c_write(0x56); //QN8007_ADDR_WRITE
i2c_write(Reg); //register name/address
i2c_write(val); //data to be written
i2c_stop();
}
////////////////////////READ//////
int qn8007_read(int Reg)
{
i2c_start();
i2c_write(0x56); //QN8007_ADDR_WRITE
i2c_write(Reg); //register name/address
i2c_start(); //restart
i2c_write(0x57); //QN8007_ADDR_READ
buffer = i2c_read(0); // read and store
i2c_stop();
return buffer;
}
----------Version Using ESP32 library "wire.h"-------------------
// QN800X_I2C_ADDRESS is 0x2b
////////////////////////WRITE////
void qn8007_write(int Reg, int val)
{
Wire.beginTransmission(QN800X_I2C_ADDRESS);
Wire.write(0x56);
Wire.write(Reg);
Wire.write(val);
Wire.endTransmission();
}
////////////////////////READ//////
int qn8007_read(int Reg)
{
Wire.beginTransmission(QN800X_I2C_ADDRESS);
Wire.write(0x56);
Wire.write(Reg);
Wire.beginTransmission(QN800X_I2C_ADDRESS);
Wire.write(0x57);
Wire.requestFrom(QN800X_I2C_ADDRESS, 2);
int buffer=Wire.read();
Wire.endTransmission();
return buffer;
} |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 502 Location: Montenegro
|
|
Posted: Fri Jan 03, 2025 4:54 am |
|
|
While I'm not at all familiar with Arduino library, I do believe wire.h uses hardware I2C that very likely expects some response from the chip to work properly. Mr. tankostz managed to command his chip using software I2C implementation. Quick search found SoftWire library for Arduino that does that. |
|
|
tonkostz
Joined: 07 May 2011 Posts: 56 Location: Bulgaria
|
|
|
Al in Michigan
Joined: 29 Dec 2024 Posts: 13 Location: michigan
|
|
Posted: Fri Jan 03, 2025 11:45 am |
|
|
PrinceNai wrote: | While I'm not at all familiar with Arduino library, I do believe wire.h uses hardware I2C that very likely expects some response from the chip to work properly. Mr. tankostz managed to command his chip using software I2C implementation. Quick search found SoftWire library for Arduino that does that. |
wire.h out and above implemented with github stevemarple's softwire.h using basically tonkostz main with my added write and read to register QN_CH Writing 0x55 and 0xaa. Still always reads 0xff. |
|
|
tonkostz
Joined: 07 May 2011 Posts: 56 Location: Bulgaria
|
|
Posted: Fri Jan 03, 2025 12:24 pm |
|
|
Frequency = 76 + 0.05*CHindex. For example 0x252 is 105.7MHz.
You have to write the lower 8 bits 0x52 to register CH and the highest 2 bits 0x02 to register CH_STEP. |
|
|
Al in Michigan
Joined: 29 Dec 2024 Posts: 13 Location: michigan
|
|
Posted: Fri Jan 03, 2025 3:23 pm |
|
|
Here is my code using stevemarple's softwire.h library and my interpretation of tonkostz example. Resulting output on the monitor is:
Start
Build:Jan 3 2025 16:06:35
tStep :ff
tStep_F :fe
First:ff
Second:ff
End Setup()
Either I've interpreted something wrong of these chips are dead.
/*nc 1 : - nc QN8007 pins
nc 2 : - nc
aGND 3 : audio Gnd - gnd
ALI 4 : L analog inp - nc
ARI 5 : R analog inp - nc
AGND 6 : Analog Gnd - gnd
RFI 7 : receiver inp - nc
rGND 8 : RF Gnd - gnd
RFO 9 : - TX Antenna
VIO 10 : def io levels - 3.3V
CEN 11 : power up - 3.3V
MOD 12 : I2C config - gnd
MCK 13 : - nc
INT 14 : - nc ??
WS 15 : I2S mode sel - nc
XCLK 16 : - nc
XTAL 17 : - nc
XTAL 18 : - nc
AGND 19 : Gnd - gnd
DIN 20 : I2S input - nc
SEB 21 : address sel - gnd (sel 0x2b)
SLC 22 : I2C - SLC 4.7K pullup
SDA 23 : I2C - SDA 4.7k pullup
Vcc 24 : - 3.3V also tried 5V
***/
#include <SoftWire.h>
#include <AsyncDelay.h>
#define QN_SYSTEM1 0x00 //!< Sets device modes.
#define QN_SYSTEM2 0x01 //!< Sets device modes, resets.
#define QN_DEV_ADD 0x02 //!< Sets device address.
#define QN_ANACTL1 0x03 //!< Analog control functions.
#define QN_REG_VGA 0x04 //!< TX mode input impedance, crystal cap load setting.
#define QN_CIDR1 0x05 //!< Device ID numbers.
#define QN_CIDR2 0x06 //!< Device ID numbers.
#define QN_I2S 0x07 //!< Sets I2S parameters.
#define QN_CH 0x08 //!< Lower 8 bits of 10-bit channel index.
#define QN_CH_START 0x09 //!< Lower 8 bits of 10-bit channel scan start channel index.
#define QN_CH_STOP 0x0A //!< Lower 8 bits of 10-bit channel scan stop channel index.
#define QN_CH_STEP 0x0B //!< Channel scan frequency step. Highest 2 bits of channel indexes.
#define QN_PAC_TARGET 0x0C //!< Output power calibration control.
#define QN_TXAGC_GAIN 0x0D //!< Sets TX parameters.
#define QN_TX_FDEV 0x0E //!< Specify total TX frequency deviation.
#define QN_GAIN_TXPLT 0x0F //!< Gain of TX pilot frequency deviation, I2S buffer clear.
#define QN_RDSD0 0x10 //!< RDS data byte 0.
#define QN_RDSD1 0x11 //!< RDS data byte 1.
#define QN_RDSD2 0x12 //!< RDS data byte 2.
#define QN_RDSD3 0x13 //!< RDS data byte 3.
#define QN_RDSD4 0x14 //!< RDS data byte 4.
#define QN_RDSD5 0x15 //!< RDS data byte 5.
#define QN_RDSD6 0x16 //!< RDS data byte 6.
#define QN_RDSD7 0x17 //!< RDS data byte 7.
#define QN_RDSFDEV 0x18 //!< Specify RDS frequency deviation, RDS mode selection.
#define QN_CCA 0x19 //!< Sets CCA parameters.
#define QN_STATUS1 0x1A //!< Device status indicators.
#define QN_STATUS3 0x1B //!< RDS status indicators.
#define QN_RSSISIG 0x1C //!< In-band signal RSSI dBμV value.
#define QN_RSSIMP 0x21 //!< Multipath signal RSSI (Received signal strength indicator) DB value.
#define QN_SNR 0x22 //!< Estimated RF input CNR value from noise floor around the pilot after FM demodulation.
#define QN_REG_XLT3 0x49 //!< XCLK pin control.
#define QN_REG_DAC 0x4F //!< DAC output stage gain.
#define QN_PAC_CAL 0x59 //!< PA tuning cap calibration.
#define QN_PAG_CAL 0x5A //!< PA gain calibration.
SoftWire sw(SDA, SCL); // ESP32 d21 d22 w/4.7K pullups
#define QN800X_I2C_ADDRESS 0x2B // See Datasheet pag. 25 (5.1 2-Wire Serial Control Interface).
#define QN800X_DELAY_COMMAND 2500 // Delay after command
int qn8007_read(int Reg)
{
sw.beginTransmission(QN800X_I2C_ADDRESS);
sw.write(0x56);
sw.write(Reg);
sw.beginTransmission(QN800X_I2C_ADDRESS);
sw.write(0x57); // setup read
sw.requestFrom(QN800X_I2C_ADDRESS, 2);
uint16_t buffer = sw.read();
sw.endTransmission();
return buffer;
}
void qn8007_write(int Reg, int val)
{
sw.beginTransmission(QN800X_I2C_ADDRESS);
sw.write(0x56);
sw.write(Reg);
sw.write(val);
sw.endTransmission();
delayMicroseconds(QN800X_DELAY_COMMAND);
}
void setup()
{
uint8_t tStep;
uint16_t freq=1073; //this is frequency in MHz*10
char str[80];
Serial.begin(115200);
delay(2000);
while(!Serial)
Serial.print("no Serial");
Serial.print("\nStart\n");
sprintf(str, "Build:%s %s\n", __DATE__, __TIME__ );
Serial.printf("%s", str);
qn8007_write(QN_SYSTEM2, 0x80); //reset all registers to default
qn8007_write(QN_SYSTEM1, 0x43); //enter transmit
qn8007_write(QN_ANACTL1, 0x2B); //select 26MHz crystal
qn8007_write(QN_SYSTEM2, 0x01); //set preemphasis to 50uS
freq = freq * 10;
freq = ((freq - 7600) / 5); //626 for 107.3MHz (0x272 or 0b1001110010) lower 8bits are (0x72 or 0b01110010)
qn8007_write(QN_CH, (uint8_t)freq);
tStep = qn8007_read(QN_CH_STEP);
Serial.printf("tStep :%x\n", tStep );
tStep &= ~0x03;
tStep |= (((uint8_t)(freq >> 8)) & 0x03);
qn8007_write(QN_CH_STEP, tStep);
qn8007_write(QN_PAC_TARGET, 70); //set power valid values from 31 to 131
//power = (0.37*PAC_TARGET+68)dB,PAC_TARGET range is 31-131
Serial.printf("tStep_F :%x\n", tStep );
qn8007_write(QN_CH, 0x55);
uint8_t val = qn8007_read(QN_CH);
Serial.printf("First:%x\n", val);
qn8007_write(QN_CH, 0x0aa);
val = qn8007_read(QN_CH);
Serial.printf("Second:%x\n", val);
Serial.print("\nEnd Setup()");
}
void loop()
{
delay(1000);
} |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Fri Jan 03, 2025 4:18 pm |
|
|
a very quik look...
saw this..
#define QN800X_I2C_ADDRESS 0x2B // See Datasheet pag. 25 (5.1 2-Wire Serial Control Interface).
CCS uses 8 bit I2C addressing, so change 0x2b to 0x56 ?? |
|
|
Al in Michigan
Joined: 29 Dec 2024 Posts: 13 Location: michigan
|
|
Posted: Fri Jan 03, 2025 6:52 pm |
|
|
Yea, tried 56 vs 2b in the past & just tried it again but no help. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Fri Jan 03, 2025 9:17 pm |
|
|
OK which PIC are you using ?
What is VDD ?
I2C bus pulllups are based upon VDD of the system. |
|
|
Al in Michigan
Joined: 29 Dec 2024 Posts: 13 Location: michigan
|
|
Posted: Fri Jan 03, 2025 9:56 pm |
|
|
temtronic wrote: | OK which PIC are you using ?
What is VDD ?
I2C bus pulllups are based upon VDD of the system. |
ESP32 (3.3v IO lines ) is microcontroller, VDD on QN8007 is 3.3V also tried 5V, I2C pullups are 4.7K to 3.3V - sharp edges well within clock edges. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Sat Jan 04, 2025 6:43 am |
|
|
ESP32 is NOT a PIC microcontroller, so you have 2 options
1) select a PIC and use CCS compiler and get lots of help here. This is an EASY project to get 'up and running'.
2) goto an ESP32 forum and ask for help |
|
|
Al in Michigan
Joined: 29 Dec 2024 Posts: 13 Location: michigan
|
|
Posted: Sat Jan 04, 2025 11:10 am |
|
|
My take is that the issue is not one of what controller is being used to control the QN8007 but instead what it takes to control the QN8007. Any PIC or any micro controller should be able to control a QN8007, the question is how to do so. I thank you for the help you have provided. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9372 Location: Greensville,Ontario
|
|
Posted: Sat Jan 04, 2025 12:23 pm |
|
|
Once you understand the QN8007 is a '2 wire interface' device and NOT I2C, then the actual code is dead simple,consisting of 'bit banging' 2 lines that have correct pullups on them with proper timing.
All that information is in the QN8007 datasheet and nowadays Google is tremendous help in filling in the gaps ! |
|
|
Al in Michigan
Joined: 29 Dec 2024 Posts: 13 Location: michigan
|
|
Posted: Sat Jan 04, 2025 5:43 pm |
|
|
temtronic wrote: | .....
All that information is in the QN8007 datasheet and nowadays Google is tremendous help in filling in the gaps ! |
EXACTLY ! And in one of those searches lead to a forum thread with someone having the same issue -- followed by a reply saying "Me Too" -- followed by a bunch of great suggestions that sadly didn't bear fruit -- followed by a seemingly irritated participant breaking into condescension -- root of reason for that not clear, suspect [spam] in a knot. |
|
|
|