Question about SPI. Sending data from master to master

Thread Starter

Morten Andersen

Joined Jun 7, 2019
25
So im doing a home project where im using an ATMEGA 2560. The goal is to send data from the MOSI to the MISO on the same board.
Im having some problems with how to attack this.

So far my code looks like this:

C:
#include <avr/io.h>
#include "I2C.h"
#include "ssd1306.h"
#define F_CPU 16000000UL
#include <util/delay.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <avr/interrupt.h>
#include "Initialize Display.h"
#include "Setup display.h"

void setup(); //setting up display for later use

unsigned char cData;

unsigned char SPI_MasterTransmit(unsigned char Cdata)
{
    SPDR = cData; //starter transmissionen
    while(!(SPSR & (1<<SPIF))); //venter på transmission bliver færdig
    return(SPDR);
}


int main(void)
{

void init_disp(); //display for later use
void SPI_Masterinit(void)
{
    DDRB = (1<<PB0) | (1<<PB1) | (1<<PB2) | (0<<PB3); // DDRB er registeret der passer til SPI. med !SS, SCK, MOSI, MISO.
    SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0); //for at enable interrupt sættes (1<<SPIE); the SPRx is for setting the clock

unsigned char cData;


    while (1)
    {


    }
}
Moderators note : Used code tags for C
 
Last edited by a moderator:

jpanhalt

Joined Jan 18, 2008
8,459
What sort of problem are you having?

MISO and MOSI are usually used for SPI. Is that included in the I2C.h include file you show?

Do you have a slave device that you are communicating with? SPI is always an exchange of bits. It is not clear whether the MOSI and MISO that you want to communicate between are on the same chip or different chips. Whichever it is, why? Why not just swap the data internally in the chip and use normal SPI communication?

Finally, are you confusing MOSI/MISO with SDI/SDO nomenclature for labels?
 
Top