SPI slave on ATmega162

Hello.

I'm studying mega162 chip and trying to implement SPI slave capability. I wanna send 8 bytes to master side and after reaching last byte get back and send again, ie continuosly.

Later I'd like to implement receiving.

So, I made the following simple code:

#include #include #include

char *data = "12345678"+0x00; char *t;

void SPI_SlaveInit(void) { DDRB = (1

Reply to
Roman Mashak
Loading thread data ...

"Roman Mashak" skrev i melding news:co3upp$2igu$ snipped-for-privacy@mpeks.tomsk.su...

and

side)

shift

I haven't studied all your code, but I found two major errors:

- You have to wait for the previous byte to be sent before you write a new value to SPDR. Something like this:

- You should write whatever data points at to SPDR, not the pointer value itself.

while (1) { if (SPSR & (1

Reply to
Jan leithe

Hello, Jan! You wrote on Thu, 25 Nov 2004 09:01:04 +0100:

Jl> I haven't studied all your code, but I found two major errors: Jl> - You have to wait for the previous byte to be sent before you write a Jl> new value to SPDR. Something like this: Jl> - You should write whatever data points at to SPDR, not the pointer Jl> value itself.

Jl> while (1) { Jl> if (SPSR & (1 data = t; Jl> } Jl> SPDR = *data; Jl> data++ Jl> } Jl> } Thank you for help with C, but unfortunately problems still remains. I suppose, it's hardware related...

With best regards, Roman Mashak. E-mail: snipped-for-privacy@tusur.ru

Reply to
Roman Mashak

Hello, Jan! You wrote on Thu, 25 Nov 2004 09:01:04 +0100:

Jl> I haven't studied all your code, but I found two major errors: Jl> - You have to wait for the previous byte to be sent before you write a Jl> new value to SPDR. Something like this: Jl> - You should write whatever data points at to SPDR, not the pointer Jl> value itself. By the way, while debugging this code in AVR studio (after modification according to your notes) I noticed that data put into SPDR register are strange. Originally I'm sending string "12345678", but character codes stored into SPDR are 0x31, 0x32, 0x33 etc.

Why ? Jl> while (1) { Jl> if (SPSR & (1 data = t; Jl> } Jl> SPDR = *data; Jl> data++ Jl> } Jl> }

With best regards, Roman Mashak. E-mail: snipped-for-privacy@tusur.ru

Reply to
Roman Mashak

That is correct. A 0x31 is the hexadecimal ASCII code for character '1',

0x32 for a '2' and so on....

Meindert

Reply to
Meindert Sprang

Hello, Meindert! You wrote on Thu, 25 Nov 2004 12:27:56 +0100:

??>> By the way, while debugging this code in AVR studio (after ??>> modification according to your notes) I noticed that data put into ??>> SPDR register are strange. Originally I'm sending string "12345678", ??>> but character codes stored into SPDR are 0x31, 0x32, 0x33 etc.

MS> That is correct. A 0x31 is the hexadecimal ASCII code for character MS> '1', 0x32 for a '2' and so on.... oh,, sorry for my stupidity :)

Anyway, I still don't get output signal looking at oscilloscope. I believe, I should make on slave side some checking of SPI is ready, SS checking or similar?

With best regards, Roman Mashak. E-mail: snipped-for-privacy@tusur.ru

Reply to
Roman Mashak

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.