Maker Pro
Maker Pro

SI4703 Radio Project

mariancap

Jun 17, 2023
5
Joined
Jun 17, 2023
Messages
5
I have to develop a project using SI4703 module to scan the posts, select it and to hear the sound on wired headphones. I can not use Arduino program i need to do the code in C language.I also need a documentation for this project about the registers ,what are the registers doing and more about the module.Interface of the module:I2C/3 WIRE SPI(I/O). I also have these observations from the teacher:

"If you select the I2C interface, then the registers are not addressable: - All 16 registers * 16 bits (= 32 bytes) must be read. - When writing, the internal address pointer starts at 0x02, the High byte. On read, the internal address pointer starts at 0x0A, the High byte -Address counter has wrap-around at 0x0F"

What should i write in documentation:
-Documentation:

All theme module component catalog sheets and module schematics can be found on Team:

Before choosing a particular module / project theme, you are required to read the documentation of the chosen component / module, and extract from the documentation:

· To which microcontroller pin (or VCC; GND, NC-Not Connected) should each pin of the module be connected.

o You can indicate the connections by drawing or by text

· There are components, which support both SPI and I2C. To these specify: in which way the interface required by the project is chosen

· For SPI interfaces:

o SPI Working Mode and Data Format

§ Maximum frequency of SCLK

o The sequence of data to be transmitted and data to be received

§ To check communication (if the module allows it: reading the ID register

§ to start the measurement (if the component in the module requires this) and read the measured data:

· Internal register address and value of the bit(s) that must be set to start the measurement (valid (if the component has this facility implemented)

· The address of the internal register and the bit, which must be checked, to know that there is valid data (if the component has this facility implemented)

· Address of the internal register(s), from which the data is read

· For I2C interfaces:

o The format of messages when transmitting and receiving data – that is, the sequences of commands to write and read a register from a specified address

§ Maximum frequency of SCL

o The sequence of data to be transmitted and data to be received

§ to start the measurement (if the component in the module requires this) and read the measured data:

· Internal register address and value of the bit(s) that must be set to start valid measurement (if the component has this facility implemented)

· The address of the internal register and the bit, which must be checked, to know that there is valid data (if the component has this facility implemented)

· Address of the internal register(s), from which the data is read

Any help whould help me.I am working on devops and i dont have a lot of time and experience to work with microcontrollers.I am final year and i need to finish this project to finalize my college.
 

Attachments

  • Doc_SI4703.pdf
    367.6 KB · Views: 2

danadak

Feb 19, 2021
677
Joined
Feb 19, 2021
Messages
677
I can not use Arduino program i need to do the code in C language.

The doc you supplied shows using Arduino boards. Arduino is modified C / C++.

Does this mean you are to use IDE from Atmel to do the coding ?



If you are not familiar with this IDE start by watching basic videos, then do a simple
flash an LED. That way you kno the basics, start a new project, do small amount of
code, while debugging (watching a variable, like a flag), etc... Save your program
on a regular basis as you work.

Break this down into pieces. Your doc shows how to connect the part.

Both the Atmel IDE and Arduino IDE have example SPI programs you can read,
examine, to get a feel. If your lab has a DSO scope you can observe the program
reading / writing serial data, eg. DSO will decode the data stream for you showing
command you are sending and response.


Web is rich rich with folks getting serial interfaces up and running, its not rocket
science nor is it trivial. Start by sending simple command and debugging the parts
response.



Youtube a great resource to learn.

When you code add comments about what the specific code line is doing, this becomes
self documenting for the project in a sense. And allows you to remember what and why you
did that line of code.

The forum will help as you post bits and pieces you are trying to get working. It wont do the task
for you.

So wire up a module, send something trivial and observe with a scope you are getting clk and data
out of your micro, both in terms of byte / word values and voltage and timing.

Hint when you use scope make sure ground probe securely fashioned to ground. A ground lead flopping
around and hitting a trace on a board can hose the board. Its easy to do, I have done a few myself.

Lastly read until you drop, until your eyeballs roll across the floor, and when that happens
read some more. As you read that which you do not understand bit by bit it starts coming
together and the learning accelerates.


Regards, Dana.
 
Last edited:

mariancap

Jun 17, 2023
5
Joined
Jun 17, 2023
Messages
5
Hi,i changed a little bit and i choosed to use I2C interface.Yes,the code need to be used in MPLABxIDE.Can you help me with more advices and informations
 

Delta Prime

Jul 29, 2020
1,642
Joined
Jul 29, 2020
Messages
1,642
Configure the I2C pins in MCC & initialize the I2C
peripherals using PLIB APIs & set the clock frequency.
IODIRClear(I2C1_SDA_PIN);
//set SDA as input
IODIRClear(I2C1_SCK_PIN); //set SCK as input
I2C1_Init();
I2C1_Start();
I2C1_MasterWrite(slaveAddress);
Use MCC to generate the I2C interrupts service routine.
Interrupts are needed for I2C communication
Go slow bit by bit.
Also...
A belated welcome to maker Pro.
:)
 

mariancap

Jun 17, 2023
5
Joined
Jun 17, 2023
Messages
5
Thank you,i hope i’ll pass this subject. I really dont like it cuz of the teacher
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,476
Joined
Nov 17, 2011
Messages
13,476
You can use the Arduino library as a starting point. As @danadak mentioned, an Arduino sketch is a slightly modified version of C/C++. Therefore the Arduino code is basically C/C++ code. There are also examples to get you started.
 

mariancap

Jun 17, 2023
5
Joined
Jun 17, 2023
Messages
5
this is what i tried to write for the i2c connection for I2C
C:
#include "Uno_Nano_utils.h"
#include "ATMega_I2C.h"
#include <util/delay_basic.h>
#include <util/delay.h>


void I2CSetup(unsigned long Frequency){
//TBWR is calculated as
// ( (F_CPU/F_SCL) - 16) /(2*Prescaler)
//where F_CPU = 8 MHZ (defined above) and F_SCL - SCL clock frequency
//we will use Prescaler value of 1
    uint8_t Temp;
    Temp = (int)( ( ((float)F_CPU/Frequency)-16.0)/2.0 + 0.5);
    TWBR = Temp;
  
}



unsigned char I2C_Write (unsigned char slaveAddress,
                         unsigned char * dataBuffer,
                         unsigned char NumBytes,
                         unsigned char StopCommand){
  
uint8_t i=0;
dataBuffer[0]=0x00;
dataBuffer[1]=0x00;
//Send START command
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (bit_is_clear(TWCR, TWINT));//wait until START is sent
//Check Status
if (I2CStatus != I2CSTA_START_SENT) return I2CStatus;


//Send Slave Address + W
TWDR = (slaveAddress << 1);
TWCR = (1<<TWINT) | (1<<TWEN);
while (bit_is_clear(TWCR, TWINT));//wait until SLA+W is sent
//Check Status
if (I2CStatus != I2CSTA_SLA_W_ACK) return I2CStatus;

//Send Numbytes Data
for (i =0; i < NumBytes; i++){
    TWDR = *dataBuffer++;
    TWCR = (1<<TWINT) | (1<<TWEN);
    while (bit_is_clear(TWCR, TWINT));//wait until Data is sent
    //Check Status
    if (I2CStatus != I2CSTA_DATA_W_ACK) return I2CStatus;   
}

if (StopCommand == STOP){
//Send STOP command
TWCR = (1<<TWINT) | (1<<TWSTO) | (1<<TWEN);
}

return 0;

}


/* ------------------------------------------------------------ */
/***  unsigned char I2CRead()
**
**    Parameters:
**        slaveAddress: the 7-bit address of the I2C slave
**      dataBuffer : Read data buffer pointer
**      NumBytes: number of data bytes to be read
**
**    Return Values:
**      0 - Transfer Successful, otherwise:
**      I2CSTA_SLA_R_NACK (0x20) - No acknowledge received from Slave after sending Address + Read, or
**
**    Description:
**  Reads data from the I2C slave
**
*/
unsigned char I2C_Read  (unsigned char slaveAddress,
                        unsigned char * dataBuffer,
                        unsigned char NumBytes){
  
 uint8_t i=0;
 uint8_t Temp =0;

//Send START command
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (bit_is_clear(TWCR, TWINT));//wait until START is sent
//Check Status both for Start or Repeated Start Condition
if ( (I2CStatus != I2CSTA_START_SENT) &&
     (I2CStatus != I2CSTA_REP_START_SENT) ) return I2CStatus;


//Send Slave Address + R
TWDR = (slaveAddress << 1) | 1;
TWCR = (1<<TWINT) | (1<<TWEN);
while (bit_is_clear(TWCR, TWINT));//wait until SLA+W is sent
//Check Status
if (I2CStatus != I2CSTA_SLA_R_ACK) return I2CStatus;

//Receive Numbytes data
for (i =0; i < NumBytes; i++){
    //Send NACK to the last byte
    if (i == (NumBytes-1)){
        Temp = (1<<TWINT) | (1<<TWEN);
        //Clear Acknowledge bit
        Temp = Temp & ~(1<<TWEA);
        TWCR = Temp;
    }
    else//send Acknowledge bit
        TWCR = (1<<TWINT) | (1<<TWEA) | (1<<TWEN);
    while (bit_is_clear(TWCR, TWINT));//wait until Data is sent

    *dataBuffer=TWDR;
    dataBuffer++;
}

//Send Stop bit
TWCR = (1<<TWINT) | (1<<TWSTO) | (1<<TWEN);


return 0; 
 
}


/* *****************************************************************************
 End of File
 */
Can you help pe it is ok?

[mod edit: put the code into a code section]
 
Last edited by a moderator:
Top