SPI communication, how to set up clock correctlyHow do you set, clear, and toggle a single bit?Implementing SPI slave ISR on PIC32?What OMAP-L138 registers should I work with to select another SPI chip?PIC24 SPI master refuses receive clock generationPIC 18F46K22 SPI speedWrite SPI dummy bytes using DMA circular modeHow to transfer data over SPI (I'm getting a null buffer)FT2232H - Irregular clock in SPI modeSPI Slave data shifted by 4 BitWhere is the SPI multiplexer of my dreams?

Why 1,2 printed by a command in $() is not interpolated?

Traversing Oceania: A Cryptic Journey

How to hide an urban landmark?

Who won a Game of Bar Dice?

Has there been a multiethnic Star Trek character?

Can I use trees and other climbable objects to get on Tenser's Floating Disk?

Someone whose aspirations exceed abilities or means

How did old MS-DOS games utilize various graphic cards?

Why not invest in precious metals?

Why are trash cans referred to as "zafacón" in Puerto Rico?

CSV how to trim values to 2 places in multiple columns using UNIX

bmatrix: how to align elements' subscripts?

Meaning of 'lose their grip on the groins of their followers'

How is the excise border managed in Ireland?

I have a problematic assistant manager, but I can't fire him

What ways have you found to get edits from non-LaTeX users?

Writing an augmented sixth chord on the flattened supertonic

What to do when surprise and a high initiative roll conflict with the narrative?

Is it possible to have a wealthy country without a middle class?

Print lines between start & end pattern, but if end pattern does not exist, don't print

English word for "product of tinkering"

Why am I getting a strange double quote (“) in Open Office instead of the ordinary one (")?

How to use memset in c++?

Generate basis elements of the Steenrod algebra



SPI communication, how to set up clock correctly


How do you set, clear, and toggle a single bit?Implementing SPI slave ISR on PIC32?What OMAP-L138 registers should I work with to select another SPI chip?PIC24 SPI master refuses receive clock generationPIC 18F46K22 SPI speedWrite SPI dummy bytes using DMA circular modeHow to transfer data over SPI (I'm getting a null buffer)FT2232H - Irregular clock in SPI modeSPI Slave data shifted by 4 BitWhere is the SPI multiplexer of my dreams?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















We are trying to set up SPI communication between a pic32 and an ADS1298. The issue is that we cannot get the clock set up correctly.



What I have tried is the following



#include <xc.h>
#include "SDlib16.h"
#pragma config FNOSC = FRCPLL // Oscillator selection
#pragma config POSCMOD = HS // Primary oscillator mode
#pragma config FPLLIDIV = DIV_2 // PLL input divider (8 -> 4)
#pragma config FPLLMUL = MUL_20 // PLL multiplier ( 4x20 = 80)
#pragma config FPLLODIV = DIV_1 // PLL output divider
#pragma config FPBDIV = DIV_2 // Peripheral bus clock divider 80/ 2= 40 mhz
#pragma config FSOSCEN = OFF // Secondary oscillator enable

#pragma config IESO=OFF
#pragma config FCKSM=CSDCMD
#pragma config OSCIOFNC=OFF

#pragma config FWDTEN = OFF // Watchdog timer enable
#pragma config WDTPS = PS4096 // Watchdog timer post-scaler
#pragma config FSRSSEL = PRIORITY_7 // SRS interrupt priority


/*
*
*/
void configpins(void)

DDPCONbits.JTAGEN = 0;//Turns off the JTAG function of all pins
AD1PCFG=0xFFFF;//Turns off the analog function of all pins
TRISBbits.TRISB8=0; //Makes RB8 an output (Chip select)
TRISBbits.TRISB12=0;//Makes RB12 an output(Hold)
TRISBbits.TRISB10=0;//Makes RB10 an output(Write protect)

void initialSPI(void)

IEC0CLR=0x03800000;//turns off SPI interrupts
SPI4CONbits.ON=0;//turns off SPI4 module
SPI4BUF=0;//Sets SPI4 buffer to 0
SPI4CONbits.ENHBUF=0;//Sets ENHBUF to zero
SPI4CONbits.CKP=0;//Sets clock phase bit to 0
SPI4BRG=0;//Sets the SPI clock to be at 20MHz(Logic analyzer cant sample high enough for 20MHz )
SPI4STATbits.SPIROV=0;//Sets overflow bit to zero
SPI4CONbits.MSTEN=1;//Sets microcontroller to master mode
SPI4CONbits.DISSDO=0;//Sets the module to control the SDO pin
SPI4CONbits.CKE=1;//Sets the clock edge bit to 1
SPI4CONbits.SMP=0;//Sets SMP bit to 0

SPI4CONbits.MODE16=0;//Turns off 16bit mode
SPI4CONbits.MODE32=0;//Turns off 32bit mode
SPI4CONbits.ON=1;// Turns on SPI4 module


unsigned char Transfer(unsigned char data)

SPI4STATbits.SPIRBF=0; //Clears the receives buffer bit
SPI4BUF = data;//Puts data into the buffer
SPI4STATbits.SPITBE=0;//Turns off buffer enable
while (!SPI4STATbits.SPIRBF);//While the Receive buffer flag is empty
return SPI4BUF; // read a byte



unsigned char SPITransaction(unsigned char data)//Simple one byte in and one out

PORTBbits.RB8=0;//clears the chip select
unsigned char CharReturned=Transfer(data);// Calls the transfer function to send byte to buffer
PORTBbits.RB8=1;//Sets the chip select
return CharReturned;//Returns the byte received from buffer


void ReadDevice(void)//Gets the Device ID

PORTBbits.RB8=0;//Clears the chip select
Transfer(0xAB);//Bytes to get the device id
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
PORTBbits.RB8=1;//Sets the Device ID

int main(int argc, char** argv)

configpins();
initialSPI();
PORTBbits.RB10=1;//Sets the Write protect to high
PORTBbits.RB12=1;//Sets Hold to high
PORTBbits.RB0=0;
while(1)// Forever loop

//unsigned char Result=SPITransaction('W');//Sends W to the buffer and gets back a byte
//ReadDevice();//Gets the Device ID
PORTBbits.RB8=0;//Clears the chip select
Transfer(0x08);//Bytes to get the device id
PORTBbits.RB8=1;//Sets the Device ID

return (EXIT_SUCCESS);



I do not know what am i doing wrong, when I hook up the clock to a logic analyzer, it does not look like a clock, instead it looks like something completely random anyone knows what am I doing wrong?










share|improve this question






















  • Sounds like a hardware or measurement problem more than anything else.

    – Lundin
    Mar 25 at 11:28

















0















We are trying to set up SPI communication between a pic32 and an ADS1298. The issue is that we cannot get the clock set up correctly.



What I have tried is the following



#include <xc.h>
#include "SDlib16.h"
#pragma config FNOSC = FRCPLL // Oscillator selection
#pragma config POSCMOD = HS // Primary oscillator mode
#pragma config FPLLIDIV = DIV_2 // PLL input divider (8 -> 4)
#pragma config FPLLMUL = MUL_20 // PLL multiplier ( 4x20 = 80)
#pragma config FPLLODIV = DIV_1 // PLL output divider
#pragma config FPBDIV = DIV_2 // Peripheral bus clock divider 80/ 2= 40 mhz
#pragma config FSOSCEN = OFF // Secondary oscillator enable

#pragma config IESO=OFF
#pragma config FCKSM=CSDCMD
#pragma config OSCIOFNC=OFF

#pragma config FWDTEN = OFF // Watchdog timer enable
#pragma config WDTPS = PS4096 // Watchdog timer post-scaler
#pragma config FSRSSEL = PRIORITY_7 // SRS interrupt priority


/*
*
*/
void configpins(void)

DDPCONbits.JTAGEN = 0;//Turns off the JTAG function of all pins
AD1PCFG=0xFFFF;//Turns off the analog function of all pins
TRISBbits.TRISB8=0; //Makes RB8 an output (Chip select)
TRISBbits.TRISB12=0;//Makes RB12 an output(Hold)
TRISBbits.TRISB10=0;//Makes RB10 an output(Write protect)

void initialSPI(void)

IEC0CLR=0x03800000;//turns off SPI interrupts
SPI4CONbits.ON=0;//turns off SPI4 module
SPI4BUF=0;//Sets SPI4 buffer to 0
SPI4CONbits.ENHBUF=0;//Sets ENHBUF to zero
SPI4CONbits.CKP=0;//Sets clock phase bit to 0
SPI4BRG=0;//Sets the SPI clock to be at 20MHz(Logic analyzer cant sample high enough for 20MHz )
SPI4STATbits.SPIROV=0;//Sets overflow bit to zero
SPI4CONbits.MSTEN=1;//Sets microcontroller to master mode
SPI4CONbits.DISSDO=0;//Sets the module to control the SDO pin
SPI4CONbits.CKE=1;//Sets the clock edge bit to 1
SPI4CONbits.SMP=0;//Sets SMP bit to 0

SPI4CONbits.MODE16=0;//Turns off 16bit mode
SPI4CONbits.MODE32=0;//Turns off 32bit mode
SPI4CONbits.ON=1;// Turns on SPI4 module


unsigned char Transfer(unsigned char data)

SPI4STATbits.SPIRBF=0; //Clears the receives buffer bit
SPI4BUF = data;//Puts data into the buffer
SPI4STATbits.SPITBE=0;//Turns off buffer enable
while (!SPI4STATbits.SPIRBF);//While the Receive buffer flag is empty
return SPI4BUF; // read a byte



unsigned char SPITransaction(unsigned char data)//Simple one byte in and one out

PORTBbits.RB8=0;//clears the chip select
unsigned char CharReturned=Transfer(data);// Calls the transfer function to send byte to buffer
PORTBbits.RB8=1;//Sets the chip select
return CharReturned;//Returns the byte received from buffer


void ReadDevice(void)//Gets the Device ID

PORTBbits.RB8=0;//Clears the chip select
Transfer(0xAB);//Bytes to get the device id
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
PORTBbits.RB8=1;//Sets the Device ID

int main(int argc, char** argv)

configpins();
initialSPI();
PORTBbits.RB10=1;//Sets the Write protect to high
PORTBbits.RB12=1;//Sets Hold to high
PORTBbits.RB0=0;
while(1)// Forever loop

//unsigned char Result=SPITransaction('W');//Sends W to the buffer and gets back a byte
//ReadDevice();//Gets the Device ID
PORTBbits.RB8=0;//Clears the chip select
Transfer(0x08);//Bytes to get the device id
PORTBbits.RB8=1;//Sets the Device ID

return (EXIT_SUCCESS);



I do not know what am i doing wrong, when I hook up the clock to a logic analyzer, it does not look like a clock, instead it looks like something completely random anyone knows what am I doing wrong?










share|improve this question






















  • Sounds like a hardware or measurement problem more than anything else.

    – Lundin
    Mar 25 at 11:28













0












0








0








We are trying to set up SPI communication between a pic32 and an ADS1298. The issue is that we cannot get the clock set up correctly.



What I have tried is the following



#include <xc.h>
#include "SDlib16.h"
#pragma config FNOSC = FRCPLL // Oscillator selection
#pragma config POSCMOD = HS // Primary oscillator mode
#pragma config FPLLIDIV = DIV_2 // PLL input divider (8 -> 4)
#pragma config FPLLMUL = MUL_20 // PLL multiplier ( 4x20 = 80)
#pragma config FPLLODIV = DIV_1 // PLL output divider
#pragma config FPBDIV = DIV_2 // Peripheral bus clock divider 80/ 2= 40 mhz
#pragma config FSOSCEN = OFF // Secondary oscillator enable

#pragma config IESO=OFF
#pragma config FCKSM=CSDCMD
#pragma config OSCIOFNC=OFF

#pragma config FWDTEN = OFF // Watchdog timer enable
#pragma config WDTPS = PS4096 // Watchdog timer post-scaler
#pragma config FSRSSEL = PRIORITY_7 // SRS interrupt priority


/*
*
*/
void configpins(void)

DDPCONbits.JTAGEN = 0;//Turns off the JTAG function of all pins
AD1PCFG=0xFFFF;//Turns off the analog function of all pins
TRISBbits.TRISB8=0; //Makes RB8 an output (Chip select)
TRISBbits.TRISB12=0;//Makes RB12 an output(Hold)
TRISBbits.TRISB10=0;//Makes RB10 an output(Write protect)

void initialSPI(void)

IEC0CLR=0x03800000;//turns off SPI interrupts
SPI4CONbits.ON=0;//turns off SPI4 module
SPI4BUF=0;//Sets SPI4 buffer to 0
SPI4CONbits.ENHBUF=0;//Sets ENHBUF to zero
SPI4CONbits.CKP=0;//Sets clock phase bit to 0
SPI4BRG=0;//Sets the SPI clock to be at 20MHz(Logic analyzer cant sample high enough for 20MHz )
SPI4STATbits.SPIROV=0;//Sets overflow bit to zero
SPI4CONbits.MSTEN=1;//Sets microcontroller to master mode
SPI4CONbits.DISSDO=0;//Sets the module to control the SDO pin
SPI4CONbits.CKE=1;//Sets the clock edge bit to 1
SPI4CONbits.SMP=0;//Sets SMP bit to 0

SPI4CONbits.MODE16=0;//Turns off 16bit mode
SPI4CONbits.MODE32=0;//Turns off 32bit mode
SPI4CONbits.ON=1;// Turns on SPI4 module


unsigned char Transfer(unsigned char data)

SPI4STATbits.SPIRBF=0; //Clears the receives buffer bit
SPI4BUF = data;//Puts data into the buffer
SPI4STATbits.SPITBE=0;//Turns off buffer enable
while (!SPI4STATbits.SPIRBF);//While the Receive buffer flag is empty
return SPI4BUF; // read a byte



unsigned char SPITransaction(unsigned char data)//Simple one byte in and one out

PORTBbits.RB8=0;//clears the chip select
unsigned char CharReturned=Transfer(data);// Calls the transfer function to send byte to buffer
PORTBbits.RB8=1;//Sets the chip select
return CharReturned;//Returns the byte received from buffer


void ReadDevice(void)//Gets the Device ID

PORTBbits.RB8=0;//Clears the chip select
Transfer(0xAB);//Bytes to get the device id
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
PORTBbits.RB8=1;//Sets the Device ID

int main(int argc, char** argv)

configpins();
initialSPI();
PORTBbits.RB10=1;//Sets the Write protect to high
PORTBbits.RB12=1;//Sets Hold to high
PORTBbits.RB0=0;
while(1)// Forever loop

//unsigned char Result=SPITransaction('W');//Sends W to the buffer and gets back a byte
//ReadDevice();//Gets the Device ID
PORTBbits.RB8=0;//Clears the chip select
Transfer(0x08);//Bytes to get the device id
PORTBbits.RB8=1;//Sets the Device ID

return (EXIT_SUCCESS);



I do not know what am i doing wrong, when I hook up the clock to a logic analyzer, it does not look like a clock, instead it looks like something completely random anyone knows what am I doing wrong?










share|improve this question














We are trying to set up SPI communication between a pic32 and an ADS1298. The issue is that we cannot get the clock set up correctly.



What I have tried is the following



#include <xc.h>
#include "SDlib16.h"
#pragma config FNOSC = FRCPLL // Oscillator selection
#pragma config POSCMOD = HS // Primary oscillator mode
#pragma config FPLLIDIV = DIV_2 // PLL input divider (8 -> 4)
#pragma config FPLLMUL = MUL_20 // PLL multiplier ( 4x20 = 80)
#pragma config FPLLODIV = DIV_1 // PLL output divider
#pragma config FPBDIV = DIV_2 // Peripheral bus clock divider 80/ 2= 40 mhz
#pragma config FSOSCEN = OFF // Secondary oscillator enable

#pragma config IESO=OFF
#pragma config FCKSM=CSDCMD
#pragma config OSCIOFNC=OFF

#pragma config FWDTEN = OFF // Watchdog timer enable
#pragma config WDTPS = PS4096 // Watchdog timer post-scaler
#pragma config FSRSSEL = PRIORITY_7 // SRS interrupt priority


/*
*
*/
void configpins(void)

DDPCONbits.JTAGEN = 0;//Turns off the JTAG function of all pins
AD1PCFG=0xFFFF;//Turns off the analog function of all pins
TRISBbits.TRISB8=0; //Makes RB8 an output (Chip select)
TRISBbits.TRISB12=0;//Makes RB12 an output(Hold)
TRISBbits.TRISB10=0;//Makes RB10 an output(Write protect)

void initialSPI(void)

IEC0CLR=0x03800000;//turns off SPI interrupts
SPI4CONbits.ON=0;//turns off SPI4 module
SPI4BUF=0;//Sets SPI4 buffer to 0
SPI4CONbits.ENHBUF=0;//Sets ENHBUF to zero
SPI4CONbits.CKP=0;//Sets clock phase bit to 0
SPI4BRG=0;//Sets the SPI clock to be at 20MHz(Logic analyzer cant sample high enough for 20MHz )
SPI4STATbits.SPIROV=0;//Sets overflow bit to zero
SPI4CONbits.MSTEN=1;//Sets microcontroller to master mode
SPI4CONbits.DISSDO=0;//Sets the module to control the SDO pin
SPI4CONbits.CKE=1;//Sets the clock edge bit to 1
SPI4CONbits.SMP=0;//Sets SMP bit to 0

SPI4CONbits.MODE16=0;//Turns off 16bit mode
SPI4CONbits.MODE32=0;//Turns off 32bit mode
SPI4CONbits.ON=1;// Turns on SPI4 module


unsigned char Transfer(unsigned char data)

SPI4STATbits.SPIRBF=0; //Clears the receives buffer bit
SPI4BUF = data;//Puts data into the buffer
SPI4STATbits.SPITBE=0;//Turns off buffer enable
while (!SPI4STATbits.SPIRBF);//While the Receive buffer flag is empty
return SPI4BUF; // read a byte



unsigned char SPITransaction(unsigned char data)//Simple one byte in and one out

PORTBbits.RB8=0;//clears the chip select
unsigned char CharReturned=Transfer(data);// Calls the transfer function to send byte to buffer
PORTBbits.RB8=1;//Sets the chip select
return CharReturned;//Returns the byte received from buffer


void ReadDevice(void)//Gets the Device ID

PORTBbits.RB8=0;//Clears the chip select
Transfer(0xAB);//Bytes to get the device id
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
Transfer(0x00);
PORTBbits.RB8=1;//Sets the Device ID

int main(int argc, char** argv)

configpins();
initialSPI();
PORTBbits.RB10=1;//Sets the Write protect to high
PORTBbits.RB12=1;//Sets Hold to high
PORTBbits.RB0=0;
while(1)// Forever loop

//unsigned char Result=SPITransaction('W');//Sends W to the buffer and gets back a byte
//ReadDevice();//Gets the Device ID
PORTBbits.RB8=0;//Clears the chip select
Transfer(0x08);//Bytes to get the device id
PORTBbits.RB8=1;//Sets the Device ID

return (EXIT_SUCCESS);



I do not know what am i doing wrong, when I hook up the clock to a logic analyzer, it does not look like a clock, instead it looks like something completely random anyone knows what am I doing wrong?







c pic spi






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 19:03









Jose MontalvoJose Montalvo

32




32












  • Sounds like a hardware or measurement problem more than anything else.

    – Lundin
    Mar 25 at 11:28

















  • Sounds like a hardware or measurement problem more than anything else.

    – Lundin
    Mar 25 at 11:28
















Sounds like a hardware or measurement problem more than anything else.

– Lundin
Mar 25 at 11:28





Sounds like a hardware or measurement problem more than anything else.

– Lundin
Mar 25 at 11:28












1 Answer
1






active

oldest

votes


















0














I think you have missed to set the SCK (clock) as output.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327428%2fspi-communication-how-to-set-up-clock-correctly%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I think you have missed to set the SCK (clock) as output.






    share|improve this answer



























      0














      I think you have missed to set the SCK (clock) as output.






      share|improve this answer

























        0












        0








        0







        I think you have missed to set the SCK (clock) as output.






        share|improve this answer













        I think you have missed to set the SCK (clock) as output.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 29 at 13:32









        boilerboiler

        393




        393



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327428%2fspi-communication-how-to-set-up-clock-correctly%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해