Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ST7540 FSK Powerline MODEM chip

Status
Not open for further replies.

DrBob13

Full Member level 2
Joined
Mar 25, 2008
Messages
142
Helped
39
Reputation
78
Reaction score
2
Trophy points
1,298
Location
UK
Activity points
2,708
st7540 проблема

Hi,
Has anyone got any experience of using this device in an embedded system? I am having great difficulty reading and writing to the control register reliably, anyone got any code or other ideas why I cannot reliably control it using the SPI port of an Analog Devices ADuC848, I have used this device before many times in master mode and had no problems. Ayone got an example of using the SPI port on the microcontroller in slave mode, this would be useful as I think this is the cause of my problem.

Thanks in advance
Bob.
 

Re: st7540 проблема

Hi,
Has anyone got any experience of using this device in an embedded system? I am having great difficulty reading and writing to the control register reliably, anyone got any code or other ideas why I cannot reliably control it using the SPI port of an Analog Devices ADuC848, I have used this device before many times in master mode and had no problems. Ayone got an example of using the SPI port on the microcontroller in slave mode, this would be useful as I think this is the cause of my problem.

Thanks in advance
Bob.

Hi BOB I know you worked on this a while ago. But have you resolved your problems with the ST7540. I have got 2 of those modems going and have coms between them and to the control registers. My problem is with unreliable reading of transmitted data. I am able to read say 1 out of 7 transmissions. Some feedback with regards to your experiences would be appreciated.
Regards RIC
 

Hello guys,
could you post some cods on st7540 that u have?
I am also working on this project
 

Hi Guys,
Have not been on this forum for a while. Yes, we did get it to work eventually but never realy got it to work as well as the datasheet promised. We got it working most of the time over about 1km but had no success at all working on cables longer than 2km and between 1 and 2km was then very error prone, especially if any significant power was being drawn from the cable. We gave up in the end and designed our own from scratch using an ancient EXAR fsk chip (still available from NJR) and a PIC microcontroller which performs rock steady over the required 10km. The problem is that the ST7540 uses a minimum of 60kHz for the carrier, this is useless over long cables due to the fact that they look like a very good low pass filter with a 3db point below 2kHz when analysed, carriers in the mid teens of kHz are quite usable with amplification and filtering and data rates of 2.4kBaud. Have you tried using it in maximum sensitivity modes, there are two, a software one set in the internal register and a much more subtle hardware one that affects the input sensitivity dramatically, it is to do with a resistor value on one of the pins I think but I cannot remember which one off-hand, a colleague of mine actually found it. If you read the data sheet very carefully it is in there but is extremely well hidden and does not at first appear to be associated with the receive circuitry!! Remember to send data into the shift register completely backwards to so that it is the correct way around when the chips iternal circuitry reads it out, that is the data in the bytes have to be backwards too.
Good luck
Bob.
 

DrBob,

I am trying to communicate with st7540 using pic18f microp.Having trouble accessing the internal register itself by spi. The chip does not respond at all.
Were u sing the same host control also?
 

DrBob,

I am trying to communicate with st7540 using pic18f microp.Having trouble accessing the internal register itself by spi. The chip does not respond at all.
Were u sing the same host control also?

Hi Davis256
Welcome to the wonderful world of the ST7540! That chip insists on being the SPI master (a monumentally stupid piece of system design in my humble opinion, making the peripheral the master!) and unless the length of the SPI word is able to be changed (as some devices can be), the microcontroller SPI port normally expects this to be an 8bit byte, so it gets as confused as hell when it receives 24 or 32 clock pulses everytime, I think this has the effect of sending the NULL byte that it receives back from the ST chip out again 2 or three times because it cannot reload the shift register in time. I do not know if the PIC18f SPI can be configured in this way as I have only used it for a simple LED controller that did not use the SPI port. Our design was based on the Analog Devices ADuC8xx device with an 8052 core.

After ripping the paint of the walls for three or four days, I gave up and wrote a software driver to program the chip, This was effectively a software shift register of the appropriate length that bit-banged the data out synchronised to the clock from the ST chip. I was fast enough in 'C', I did not need assembly language. This worked fine and the chip then started to respond as expected. Please note that it is essential to send the bit out in revese order, that means that the bytes are sent out in reverse order and with the individual bits revesed too. We did not use the device in synchronous mode for its normal comms so I do not know if this would work once the chip has been set-up OK, are you intending to use simple asynchronous comms or synchronous?

I hope this helps, I do not have any sample code on my home computer at the moment, so cannot send you any just now. A colleague used my code as a basis for another driver for an Infineon chip and that worked OK as well. That ST chip is an absolute sh***er to work with, so good luck, When I got it sorted out the rest of the firmware in our powerline modem was quite staight forward, but its range was insufficient for our needs, so in the end so we designed one from scratch and that works fine.
Best regards,
Bob.
 

    V

    Points: 2
    Helpful Answer Positive Rating
good Morning

I am working with ST7540 and I am having problems in the communication spi. I want to communicate the chip ST7540 with PIC16F877A
but the chip doesnt respond. I followed the datasheet's guidelines for to configurate but dont worked.
Does Some one has a code in C for help me?
thanks for help
 

Hi,

Last year I was looking a code example for ST7540 and I did not success than I created one in microbasic that reads 24bit from registers with 18F46K22 SPI2 interface. It was the starting point. Now I am trying to create as C code to use in "short distance communication" to build up kind of home network. All suggestions or code examples are welcome

module ST7540Module
' This module contains necessary routines to reach via Pic Hardware SPI2 port to ST7540 SPI interface
dim

ST7540Reg as byte [6]
'ST7540Reg1 as byte ' ST7540 Register storage first part of 24 bits
'ST7540Reg2 as byte ' ST7540 Register storage second part of 24 bits
'ST7540Reg3 as byte ' ST7540 Register storage third part of 24 bits
'ST7540Reg4 as byte ' ST7540 Register storage fourth part of 48 bits
'ST7540Reg5 as byte ' ST7540 Register storage fifth part of 48 bits
'ST7540Reg6 as byte ' ST7540 Register storage sixth part of 48 bits
Spi_DataReady as byte ' Cycle temp for Reading and writing 8 byte registers
Sub procedure Read7540Registers ()
Sub procedure Send7540Registers (dim byref datax as string[48])
Sub function Read7540PowerLine() as byte
Sub Procedure Send7540PowerLine(dim byref buffer as byte)
Sub procedure PrintByte2Bin(dim mydata as byte)
sub procedure Byte2Binary(dim byte_in as byte, dim byref str_out as string[8])
sub procedure SPI2ST7540_doPacket
implements
Sub procedure Read7540Registers ()
dim i as byte
SSP2CON1 = %00000101 ' SSP2 Disable
SSP2CON2 = 0
SSP2CON3 = %00010000
SSP2STAT = %01000000
INTCON2 = %10000000 ' PortB pull ups disable
PIR3 = 0 ' SSP2IF clear with others
loop2:
while portd.0 = 1
goto loop2
wend
loop1:
if portd.0 = 0 then ' Clock idle
Latd.3 = 1 ' ST7540 Register Mode
delay_us (850) ' Wait ST7540 TCC Time to read data
SSP2CON1 = %00100101 ' SSP2 Enable as slave, No_SS
PIR3.SSP2IF = 0 ' Clear Interrupt Flag
else
goto loop1
end if
for i = 0 to 3
loop3:
if PIR3.SSP2IF <> 0 then ' if SPI2 Interrupt <> 0
ST7540Reg = SSP2BUF ' Reads the SPI2 Buffer to byte array
SSP2CON1 = %00000101 ' SSP2 Disable
PIR3.SSP2IF = 0 ' Clear SSP2 buffer full interrupt flag !!
SSP2CON1.7 = 0 ' Clears if there is any Write Collision.
SSP2CON1.6 = 0 ' Clears if there is any overflow
SSP2CON1 = %00100101 ' SSP2 Enable as slave, No_SS
PIR3.SSP2IF = 0 ' Clear SSP2 buffer full interrupt flag !!
else
goto loop3
end if
next i
Latd.3 = 0 ' Reg/Data back to "Data Mode"
end sub

Regards,
 

hello embebed work

I created a c code, but it didnt work. I dont know that's wrong.
I talked with ST's technical support but I still could not. They talked me which the watchdog can be disturbing. I dont disable it because could not
communicate anything

folow the code down


//#pragma orgall 0x004
//________________________________________________________________________________
//**********************INICIALIZANDO LCD*****************************************
// LCD module connections
sbit LCD_RS at RB1_bit;
sbit LCD_EN at RB0_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;


sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB0_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;

// End LCD module connections
//**********************INICIALIZANDO SPI***************************************

sbit Spi_CLK at RC3_bit;
sbit Spi_SDI at RC4_bit;
sbit Spi_SDO at RC5_bit;

sbit Spi_CLK_Direction at TRISC3_bit;
sbit Spi_SDI_Direction at TRISC4_bit;
sbit Spi_SDO_Direction at TRISC5_bit;

//______________________________________________________________________________
//************************INICIALIZA VARIAVEIS**********************************
char txt1[] = "iniciar";
char txt2[] = "verificar";
char txt3[] = "sistema ok";
char txt4[] = "recebido";
char txt5[] = "D1 comunicacão";
char txt6[] = "D0 configuracao";
char txt7[] = "frequencia";
char txt8[] = "D0 a D7";
char txt9[] = "configurar";
char txt10[7];
char txt11[7];
char txt12[] = "dados config";
char txt13[] = "comunicar" ;
char txt14[] = "Digite comando" ;
int a, i, x;
int com;
int dado[3];
//***********************VARIAVEIS ST7540**********************************
sbit CD_PD at RA5_bit;
sbit REG_DATA at RA4_bit;
sbit RXTX at RA3_bit;
sbit BU_THERM at RA2_bit;
sbit SPIUART at RA1_bit;
sbit WD at RA0_bit;
//************************INTERRUPÇÃO*******************************************
void interrupt()
{
if (PIR1.SSPIF) {
dado[a] = SSPBUF;
a++;
com = 1;
PORTC.F2=1 ; // interrupção de dado recebido SPI
PIR1.SSPIF=0;
}
}
//************************INICIALIZA VARIAVEIS**********************************

void main()
{
{
//*************** seta portas como entrada ou saida***************
TRISA=0b00101; // configuração do CI
TRISB2_bit = 0; // setando pino b2 como saida 7
//TRISC = 0b00011000; // 0b0011000 c0,c1,c2,c5,c6 saidas e c3,c4 entradas
TRISD = 0xff; // seta a portaD como entrada
//********************** seta registradores***********************
ADCON1 = 0x06; // todos os pinos Digital
INTCON = 0b11000000; // habilita interrupção geral de de periféricos
PIR1.SSPIF=0; // condição de interrupção
PIE1.SSPIE=1; // habilita interrupção SPI
//******************** inicializa os pinos*************************
/* Spi_CLK_Direction = 1;
Spi_SDI_Direction = 1;
Spi_SDO_Direction = 0; */
PORTB.F2 = 0 ; // pino R/W configurado para escrita no LCD
PORTA = 0;
PORTC.F2 = 0;
WD = 1;
//*************** define valores para variaveis***************
i=0; // variaveis
X=0;
a = 0;
com = 0;
}
//************************INICIALIZA FUNÇÕES************************************
{
UART1_Init(2400);
Lcd_Init(); // inicializa o LCD
SPI1_Init_Advanced(_SPI_SLAVE_SS_DIS, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
} // inicializa o spi, <registrador SPCON e SSPAT>
//************************ROTINA INICIO*****************************************
{
{ // iniciando rotina
Lcd_Cmd(_LCD_CLEAR); // limpa display
Lcd_Out(1,1,txt1); // escreva na primeira linha
Delay_ms(500);
Lcd_Out(1,1,txt2);
Delay_ms(500);
}
while (1) // loop infinito
{
while(x==0) { // loop de verificação teclas
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,txt5); // D0 comunicação
Lcd_Out(2,1,txt6); // D1 configuração
WD = 1;
Delay_ms(500);
//*****************************RX SPI*******************************************
if (com==1){ Lcd_Cmd(_LCD_CLEAR);
IntToStr(dado[0], txt10); // converter variavel int para String
Lcd_Out(1,1,txt10);
Delay_ms(1000);
}
//************************teclas de seleção*************************************
if (PORTD.F0==1) { i = 1; // verifica o botão D0 configura
x = 2;
}
if (PORTD.F1==1) { i = 2; // verifica o botão D1 comunica
x = 2;
}
if (PORTD.F2==1) { i = 3; // verifica o botão D0 leitura de parametros
x = 2;
}
}
//************************função configuração***********************************
switch (i) { // aciona funções de acordo com a tecla
case 1: Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,txt9); // neste passo será inciado a configuração
Delay_ms(500);
//***************setando variaveis**************************
REG_DATA = 1; // acessar host de controle
RXTX = 1; //rxtx em nivel baixo devido ao pullup
dado[0] = 0x13; // bits de configuração 23 - 16
dado[1] = 0xF2; // bits de configuração 15 - 8
dado[2] = 0xB0; // bits de configuração 7 - 0
//*****************enviando dados via SPI*******************
SSPBUF = dado[0];
i = 0;
break; // FINALIZA O CASE
//************************função comunicação************************************
case 2: Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,txt13); // neste passo será iniciado a comunicação
Delay_ms(500);
while(1){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,txt14);
Delay_ms(500);
WD = 0;
REG_DATA = 0; // acessar host de controle
RXTX = 0; //rxtx em nivel baixo devido ao pullup
//***************botão D0**************************
if (PORTD.F0==1){ dado[0] = 0x01;
Lcd_Cmd(_LCD_CLEAR);
IntToStr(dado[0], txt10); // converter variavel int para String
Lcd_Out(1,1,txt10);
SPI1_Write(dado[0]);
Delay_ms(500);
}
//***************botão D1***************************
if (PORTD.F1==1){ dado[0] = 0x02;
Lcd_Cmd(_LCD_CLEAR);
IntToStr(dado[0], txt10); // converter variavel int para String
Lcd_Out(1,1,txt10);
Delay_ms(500);
}
//***************botão D7***************************
if (PORTD.F7==1){ // sair comunicação
break;
i = 0;
}
}
break;

//************************FUNÇÃO LEITURA****************************************
case 3: Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,txt12); // neste passo será inciado a leitura de parametros
Delay_ms(500);
//***************setando variaveis**************************
REG_DATA = 0; // acessar host de controle
RXTX = 0; //rxtx em nivel alto devido ao pullup
i = 0;
SPIUART = 1;
UART1_Write(01);
Delay_ms(100);
UART1_Write(02);
Delay_ms(100);
UART1_Write(03);
Delay_ms(100);
UART1_Write(04);
Delay_ms(100);
UART1_Write(05);
Delay_ms(100);
UART1_Write(06);
Delay_ms(100);
break;
}
//*****************************INICIALIZAÇÃO DE LOOPS***************************
x = 0;
i = 0;
// WD = 1;
//************************ ******************************************
}
}
}
 

Dear Cleber,

I'm still fighting with creating as C code at this moment I can read config registers via SPI2 of 18F46K22 succesfully with the code below. This is written for MicrochipC18 compiler with mplab.adapted to the microchip TCPIP to work with web gui.

First need to add pin config in your project related with your hardware:
// ST7540 I/O PINS

#define ST7540_CLK_TRIS (TRISDbits.TRISD0) // From ST7540 Clock pulse to MCU *in*
#define ST7540_CLK (PORTDbits.RD0)
#define ST7540_CD_TRIS (TRISBbits.TRISB1) // From ST7540 Carrier, preamble or frame header detect *in*
#define ST7540_CD (PORTBbits.RB1) // "1" No carrier, preamble or frame header detected - "0" Carrier, preamble or frame header detected
#define ST7540_SDI_TRIS (TRISDbits.TRISD1) // From ST7540 RX data input.*in*
#define ST7540_SDI (PORTDbits.RD1)
#define ST7540_SDO_TRIS (TRISDbits.TRISD4) // To ST7540 TX data output **out**
#define ST7540_SDO (LATDbits.LATD4)
#define ST7540_RXTX_TRIS (TRISDbits.TRISD2) // To ST7540 Rx or Tx mode selection input. **out**
#define ST7540_RXTX (LATDbits.LATD2) // "1" - RX Session - "0" - TX Session
#define ST7540_REG_TRIS (TRISDbits.TRISD3) // To ST7540 Mains or control register access selector **out**
#define ST7540_REG (LATDbits.LATD3) // "1" - Control register access - "0" - Mains access
#define ST7540_BU_TRIS (TRISBbits.TRISB2) // Band in use/Thermal Shutdown event detection Input. *in*
#define ST7540_BU (PORTBbits.RB2) /* In Rx mode:
#define disablespi2 "1" Signal within the programmed band
"0" No signal within the programmed band
In Tx mode:
"1" - Thermal Shutdown event occurred
"0" - No Thermal Shutdown event occurred
(signal not latched)*/

---------- Post added at 03:00 ---------- Previous post was at 02:54 ----------

https://obrazki.elektroda.pl/53_1338076759.jpg
Then need to configure SPI2
// Configure SPI2

SSP2CON1 = 0b00000101; // Disable SSP2,SPI Slave mode, clock = SCKx pin, SSx pin control disabled, SSx can be used as I/O pin
SSP2CON2 = 0b00000000;
SSP2CON3 = 0b00010000;
SSP2STAT = 0b00000000; // Idle to active clock state,Buffer empty,
INTCON2 = 0b10000000; // PortB pull ups disable

// Configure ST7540 Connections
ST7540_REG_TRIS = 0; // Out
ST7540_CD_TRIS = 1; // In
ST7540_RXTX_TRIS = 0; // Out
ST7540_BU_TRIS = 1; // In
ST7540_REG = 0; // Startup default Mains Access
ST7540_RXTX = 1; // Startup default Rx Mode


---------- Post added at 03:08 ---------- Previous post was at 03:00 ----------

Finally you can read Config of ST7540 with the code below
ps: I'll add some interrupt for more stability but it is communicate with ST7540 and shows values on web gui you will have 24bit configs as buffer[1],buffer[2],buffer[3]. I'll put here better explanation when I complete the code to use all functions over web gui.

/*******************************************************************
* ST7540 Read Write function definitions *
********************************************************************/

void gets7540reg (unsigned char buffer[3])
{
char i = 0; // Length counter
SSP2CON1 = 0b00000101; // Disable SPI2
ST7540_RXTX = 1; // This is Rx session,
ST7540_REG = 1; // send read register command
SSP2CON1 = 0b00110101; // Enable SPI2
while(PIR3bits.SSP2IF == 0); // Wait for data to be received
buffer[1] = SSP2BUF; // Get a character from the SPI2 (MSB...to....LSB)
PIR3bits.SSP2IF = 0; // clear the SPI2 interrupt flag.
while(PIR3bits.SSP2IF == 0); // Wait for data to be received
buffer[2] = SSP2BUF; // Get a character from the SPI2 (MSB...to....LSB)
PIR3bits.SSP2IF = 0; // clear the SPI2 interrupt flag.
while(PIR3bits.SSP2IF == 0); // Wait for data to be received
buffer[3] = SSP2BUF; // Get a character from the SPI2 (MSB...to....LSB)
PIR3bits.SSP2IF = 0; // clear the SPI2 interrupt flag.
SSP2CON1 = 0b00000101; // Disable SPI2
ReadMains (); // switch to mains mode

}
 

Hello Embebed world

I am adapting your code for which to use in my pic.
but I want to know: Did you have some problem with hardware?
when I connect the chip's hardware on my pic, the CLR/T Signal attenuated.
The signal fell of 5V for 1V.
I thank if you can me help.
 

Hi cleber,

please check you are not driven CLR/T by pic port. if you connecting it directly to the pic and it attenuates the signal this sounds like port configuration on the pic or defect chip to me. I do not have any hardware problem until now but I am still working on register write side of ST7540. My hardware which is I am working with has optocouplers between pic and ST7540 for insulation.
 

Hi embebed world

Do you use optocouplers between the signals SPI too?
Could you add me on msn so we can speed our contact?
My MSN is cso_ee@hotmail.com.

Thanks
 

Hi Cleber,

I send you email about my hardware to see which parts I am using. Yes I am using optocouplers between ST7540 and Pic18F46K22 for insulation purpose.
 

Hi DrBob13,

Could you kindly help me with my problem regarding to the chip, I have send you a pm. Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top