This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SN65HVS88x SPI interface not returning values

Other Parts Discussed in Thread: SN65HVS882, ISO7241C

I have wired an sn65hvs882 to an atmega 32 processor. Earlier I tried the same with an atmega328p and arduino board. Either ways, I am not able to get the input status over spi. I know that I am doing something. After a weeks try I need help now. 

Following is the Code paste. 

/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.1b Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date : 6/11/2013
Author : Dev6
Company : xyz
Comments:


Chip type : ATmega32
Program type : Application
AVR Core Clock frequency: 11.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 512
*****************************************************/

#include <mega32.h>

// Standard Input/Output functions
#include <stdio.h>
#include <delay.h>
unsigned char data,a;

// SPI interrupt service routine
interrupt [SPI_STC] void spi_isr(void)
{
puts("received data is:") ;
data=SPDR;
putchar(data);
// Place your code here

}

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=Out Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=T State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xB0;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=0xFF
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x47;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC disabled
ADCSRA=0x00;

// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 171.875 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0xD2;
SPSR=0x00;

// Clear the SPI interrupt flag
#asm
in r30,spsr
in r30,spdr
#endasm

// TWI initialization
// TWI disabled
TWCR=0x00;

// Global enable interrupts
#asm("sei")

while (1)
{
// Place your code here
delay_ms(1000);

a=getchar();
PORTB.4=0;//CHIP SELECT

SPDR=a;
delay_ms(300);
PORTB.4=1;

}
}

  • Hi Suresh,

    Unfortunately, I will not be able to help you much in terms of debugging your code for the Atmel µC, but I can offer some points to check. Something that would really help de-bug this issue is if you could send me a oscilloscope capture of the SPI lines (/LD, /CE, CLK and SOP). We can then verify if what you are doing, is in line with how the device operates. Some points that may help you de-bug:

    • IP7 is the first bit that is clocked out serially on SOP
    • Data is clocked out (changes) on the rising edge of CLK, not the falling edge
    • the /LD pin needs a falling edge to latch the inputs and then a rising edge to serially clock out the right data. If the pin stays low, the device will only clock out IP7 over and over again
    • /CE needs to be low to clock data out

    If you can give me some more information, I can try to help you more.

    Thanks,

    John

  • Hi John

    First of all, thanks for the reply. We did for follow all the points mentioned in the pdf and also another pdf iif training digital input serializer. We have kept the CE permanently low. All other connections are as per the manual.  We suspect some error in the sequence of coding.

    We tired coding in various ways using, arduino, codevisiion etc.  We also have msp 430 and the TI am335x ICE evaluation board. I would appreciate if there is any example code which can be used to test. From there we can port the atmega.. Any C code segment will help us in understanding the sequence of data polling. 

    Thanks

    Suresh

  • Hi John

    We were working it the other way with the LD. Since LD had a bar on top my programmer assumed the reverse. As per your instruction, after changing the LD we were able to get teh proper output. Thanks a lot

    Suresh

  • Request one help with the serializer SN65HVS882.

    It works fine without the ISO7241C. But when we put the  ISO7241C we are not able to get any data. We tried wiring the ISO7241 isolation IC with another SPI device (MCP 4902) . Here we were able to get the mcu interface with the SPI device. But the same does not happen with the Serializer. 

    Can some body help. We followed the wiring as in the manual. Also we put the capacitors closer to the ISo 7241 as mentioned.

     

  • Hello Suresh,

    at first I'd like to mention that the HVS882 has a typical "shift-register" interface which can be made working with an SPI controller. Some years ago when the device was released and the data sheet created, it was decided to call it SPI compatible. Unfortunately true SPI does not have a "strobe" signal, such as the "Load-pulse" required to load the shift-register within the HVS882 before being able to transmit data.

    However, a good starting point is that you already managed to get the interface working without the isolator.

    1) Here I recommend to take a scope-picture of the interface pins at the HVS882 (/CE, /LD, SIP, SOP).

    2) Then insert the isolator and take another scope-picture of the same pins.

    3) Then compare both scope-pictures, voltage-level wise and time-wise.

    4) From the signal states at the HVS882 conclude backwards, what signal transitions must occur and when at the  controller output.  

    If you have these scope pictures please feel free to send them to me so we can have a look at them as well.

    May I ask at what data rate you are running the interface?

    Thank you and best regards, Thomas

  • Hi Suresh,

    Could you share a schematic of your board? This will clear up a lot of little questions like the power supply voltages and if the EN pins are tied high or controlled by a GPIO. Also, if you could get an oscilloscope capture of the SPI pins on the SN65HVS882 device, that would really help.

    Lastly, what speed are you clocking the data at? I am thinking you may be running into a propagation delay issue. If data is clocked out at the rising edge of the SN65HVS882 device, and then is clocking into the micrcontroller on the falling edge, then you only have less than half the period of the clock for the data to propagate from the device to the micro. Depending on the supply voltage of the isolator this delay can be as high as 70ns in one direction. That means there is a round trip delay of 140ns maximum.

    I will be able to help you more, once I have some of this information.

    Thanks,

    John

  • Sorry, we must have been writing reponses at the same time. Thanks Thomas.

    Suresh, let us know when you have some more data.

    John