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.

[SOLVED] No clock signal at sck pin in spi communication

Status
Not open for further replies.

Pushpkant

Member level 1
Joined
May 17, 2014
Messages
39
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Location
India
Activity points
451
I am trying to send data from one atmega8 to another atmega8 using the spi.
But on the master mpu there is no clock signal at sck pin.
 

amit.kumar11

Member level 5
Joined
Jun 22, 2015
Messages
86
Helped
20
Reputation
40
Reaction score
19
Trophy points
8
Location
Bangalore
Activity points
471
Hi,

Check in software, SPI initialisation , clock setting and other stuffs.
 

Pushpkant

Member level 1
Joined
May 17, 2014
Messages
39
Helped
2
Reputation
4
Reaction score
2
Trophy points
8
Location
India
Activity points
451
I am using the following code:


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// SPI master to send data to another MCU
 
#include<avr/io.h>
 
#define DDR_SPI DDRB
#define DD_MOSI PB3
#define DD_SCK  PB5
#define DD_SS   PB2
 
void SPI_MasterInit(void)
{
    /* Set MOSI and SCK output and SS as output, all other input */
    DDR_SPI = ( 1 << DD_MOSI) | ( 1 << DD_SCK) | ( 1 << DD_SS);
 
    /* Enable SPI, Master, set clock rate */
    SPCR = ( 1 << SPE) | ( 1 << MSTR) | (1 << SPR0) | (1 << SPR1);
 
    return;
}
 
void SPI_MasterTransmit(char cData)
{
    /* Start Transmission */
    SPDR = cData;
 
    /* Wait for transmission to complete */
    while(~(SPSR & (1 << SPIF)))
    {
    }
 
    return;
}
 
void msdelay(unsigned long itime)
{
    unsigned long i,j;
    
    for(i=0; i< itime; i++)
    {
        for(j=0; j<1000; j++)
        {}
    }
    return;
}
 
 
 
int main()
{
    unsigned int i;
    i=0;
 
    DDRC = 0xFF;
    DDRD = 0xFF;
    
    SPI_MasterInit();
 
    while(1)
    {
        SPI_MasterTransmit(i);
        PORTD = i;
        msdelay(1);
        i++;
    }
    
    return 0;
}



- - - Updated - - -

I don't know why the previous code is not running. But this one is OK,
I am getting the clock signal now at SCK Pin.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// SPI_test 2
 
#include<avr/io.h>
 
void SPI_Init(void)
{
    DDRB |= (1<<2) | (1<<3) | (1<<5);   //SCK, MOSI and SS as output
    DDRB &= ~(1<<4);                    //MISO as input
 
    SPCR |= (1 << MSTR);                //set as master
    SPCR |= (1 << SPR0) | (1 << SPR1);  //set spi clock as fck/128
    SPCR |= (1 << SPE);                 // enable the spi
    
    return;
}
 
 
void SPI_Master_Tx(unsigned char data)
{
    SPDR = data;
 
    while(!(SPSR & (1<<SPIF)))
    {
    }
    
    return;
}
 
void msdelay(unsigned long itime)
{
    unsigned long i,j;
 
    for(i=0; i<itime; i++)
    {
        for(j=0;j<1000; j++)
        {
        }
    }
 
    return;
}
 
int main()
{
    unsigned char i=0;
 
    DDRC = 0xFF;
 
    SPI_Init();
 
    while(1)
    {
        SPI_Master_Tx(i);
        PORTC = 0x55;
        msdelay(10);
        PORTC = 0xAA;
        msdelay(10);
    }
    return 0;
}

.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top