Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Adafruit MAX31865 is not sending data
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
_jarek_

Bascom Member



Joined: 06 Aug 2014
Posts: 5

poland.gif
PostPosted: Mon Jan 15, 2024 7:40 pm    Post subject: Reply with quote

You wrote down the configuration, and have you tried to read it and check if it is sure that SPI is working?
Back to top
View user's profile
murmel

Bascom Member



Joined: 13 Oct 2014
Posts: 17

germany.gif
PostPosted: Tue Jan 16, 2024 1:39 pm    Post subject: Reply with quote

Hello Przemek,

what is meant by PoR?

Regards
Murmel
Back to top
View user's profile
programmista123

Bascom Member



Joined: 31 Jan 2018
Posts: 141

poland.gif
PostPosted: Tue Jan 16, 2024 1:44 pm    Post subject: Reply with quote

Hi,

It's Power-On Reset.

Regards,
Przemek
Back to top
View user's profile
murmel

Bascom Member



Joined: 13 Oct 2014
Posts: 17

germany.gif
PostPosted: Tue Jan 16, 2024 2:12 pm    Post subject: Reply with quote

Thanks!!!
Back to top
View user's profile
murmel

Bascom Member



Joined: 13 Oct 2014
Posts: 17

germany.gif
PostPosted: Sun Jan 28, 2024 6:33 pm    Post subject: Reply with quote

@programmista123
which address should I read?

Greetings
Murmel
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Jan 28, 2024 7:00 pm    Post subject: Reply with quote

He seens to tell you to do your readouts only after you power on the whole circuit.

After powering on obviously it is a POR, in contrary to a reboot by code failure, brown out, jump to 0, or watchdog reset.
The case of reboot can be found out by reading MCUCR/MCUCSR, in case of Bascom controller register R6, but this seems unimportant for this purpose.
It may help to blink a LED at startup to detect undesired reboots.
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Sun Jan 28, 2024 9:35 pm    Post subject: Reply with quote

I think MCU power on reset is not the case here.
We talking about MAX PoR.

You can read showed registers and print them.
Like is shown in the picture addresses from&H00 to &H02 should have zeros but &H03 and &H04 should give you the result of &HFF.

So you can also write something to the &H80 address and then read it back by reading &H00
You should get the same value.

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Sun Jan 28, 2024 10:14 pm    Post subject: Reply with quote

EDC wrote:
I think MCU power on reset is not the case here.

Sure. Very Happy

Most time it was fun to help a user to solve problems himself, imho lack of responsiveness and lack of own efforts of the TO, combined with quite some discrepancy between actual and the required skills will make this case extra straining.
It will work if you write him his code, otherwise this will become a pretty long thread.
I may be wrong of course, and it's only page number two. Wink
Back to top
View user's profile
murmel

Bascom Member



Joined: 13 Oct 2014
Posts: 17

germany.gif
PostPosted: Tue Jan 30, 2024 5:50 pm    Post subject: Reply with quote

Hello EDC,

Reading out the addresses 01h, 02h, 03h and 04h always resulted in 7Fh (127). No config word was sent.

@MWS Unfortunately I can't work on the project every day, so there are always breaks until the next answer. I have to admit that, unlike you, I'm not an expert when it comes to Bascom. That's exactly why I'm happy about people like EDC and Przemek who offer their help without complaining.

Greetings
Murmel
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Jan 30, 2024 8:55 pm    Post subject: Reply with quote

Now we find the cause.... Very Happy
For SPI to be in MASTER MODE its SS pin MUST be configured as OUTPUT nomather what because if this pin is set low externally then uC will switch SPI back into SLAVE MODE. This will be done only if pin SS is an INPUT. Characteristis are the readings then ... 127 Very Happy

You can use PORTB.4 for anything you want and it not must be used as CS (SS) but it must be used in OUTPUT MODE.

You use PORTB.2 on Mega32 for CS and this is the port of SPI so I fistly think that this is a proper SS pin (this is true for Mega328P). But today I look into datasheet and saw this ... Very Happy



Please config PORTB.4 as output and then test again Wink

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Jan 30, 2024 10:03 pm    Post subject: Reply with quote

EDC wrote:
Now we find the cause.... Very Happy
For SPI to be in MASTER MODE its SS pin MUST be configured as OUTPUT nomather what...

This is not correct, it can be set to input and pulled high, it does not need to be an output.
From the data sheet:
Quote:
If SS is configured as an output, the pin is a general output pin which does not affect the SPI system. Typically, the pin will be driving the SS pin of the SPI Slave. If SS is configured as an input, it must be held high to ensure Master SPI operation.

Btw., this was my first reply after the opening post:
MWS wrote:
See the datasheet, to hold the SPI in Master-mode (the only mode implemented in Bascom) you either have to:
- set SS (PB4) to output
- set SS to input and pull high, can be done by internal pullup

You just learned the earth is a sphere Laughing Laughing Laughing Laughing Laughing

And this is also the reason the TO still botches around with his circuit, he asks, but does not learn from the replies.
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Tue Jan 30, 2024 10:18 pm    Post subject: Reply with quote

I joined to this topic little late and when I saw that, after many replies, problem persist then I maybe dont read them all carefully enough Wink

I know that niuanses about SS Input/Output but dont want to elaborate about everything so I wrote it simple.

I think that my picture will be more than thousants of words for that user and finally solve his problem.

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Jan 30, 2024 10:41 pm    Post subject: Reply with quote

murmel wrote:
@MWS Unfortunately I can't work on the project every day, so there are always breaks until the next answer.

You've started this thread with an outcry of needing urgent help.
Urgent however means ... well, urgent in a timely manner. Don't you feel it's unfair to call for speedy help only to hang behind?
Quote:
I have to admit that, unlike you, I'm not an expert when it comes to Bascom.

In this case it's not much about Bascom, but the exact protocol to init and drive the chip.
I don't know anything about the chip, but I know to read a data sheet.
In this case your problem is already to correctly drive the SPI interface, for that matter I tried to help you.
Quote:
That's exactly why I'm happy about people like EDC and Przemek who offer their help without complaining.

My solution to your problem was no complaint at all, see the second post of this thread.
EDC just 're-invented' it, but it's exactly the same.
Alas with your current skill-level, you would not recognize a correct answer, even if it would jump right into your face.
Back to top
View user's profile
murmel

Bascom Member



Joined: 13 Oct 2014
Posts: 17

germany.gif
PostPosted: Sun Feb 04, 2024 9:04 am    Post subject: Reply with quote

Hello EDC,
I defined the SS pin as the output and placed it across the pullup resistor to 5V.
The result is Rtd_h = 0 and RTD_l =0. The CS pin of the MAX is connected to PinB.2.
Here is the code:

'**************************************************************************************************
' Programmcode z.T. von H.Kipnik https://www.roboternetz.de/community/archive/index.php/t-75139.html
'
' https://www.analog.com/media/en/technical-documentation/data-sheets/max31865.pdf
'**************************************************************************************************

$regfile = "m32def.dat" ' CPU
$crystal = 16000000 ' Frequenz
$baud = 19200 ' use baud rate
$hwstack = 80 ' HW stack
$swstack = 80 ' SW stack
$framesize = 80 ' Frame space

Config Lcd = 20x4
Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7 , E = Portc.7 , Rs = Portc.6
Config Lcdbus = 4
Cursor Off : Cls

Config Portb.1 = Output ' Backlight LCD
Portb.0 = 1

Config Portb.2 = Output ' CS for MAX31865
Max_cs Alias Portb.2
Max_cs = 1

Config Portb.4 = Output ' SPI Master on
Portb.4 = 1

Waitms 500

Config Spi = Hard , Interrupt = Off , Data_order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 128 , Noss = 0

Spiinit

Dim Rtd As Integer 'Integer
Dim Rtd_l As Byte At Rtd Overlay
Dim Rtd_h As Byte At Rtd Overlay + 1
Dim Temperatur As Single 'Single
Dim Write_address As Byte
Dim Read_address_1 As Byte
Dim Read_address_2 As Byte
Dim Max_31865_config_register As Byte ' config register

Write_address = &B10000000 ' Config writeaddress
Read_address_1 = &B00000001 ' RTD_h Read Address
Read_address_2 = &B00000010 ' RTD_l Read Address

Max_31865_config_register = &B11100011 ' MAX-configuration

Max_cs = 0
Spiout Write_address , 1 ' write config register
Spiout Max_31865_config_register , 1
Max_cs = 1

'***************** Mainloop *********************
'(

Max_cs = 0 ' read Highbyte MSB
Spiout Read_address_1 , 1
Spiin Rtd_h , 1
Max_cs = 1

Max_cs = 0 ' read Lowbyte LSB
Spiout Read_address_2 , 1
Spiin Rtd_l , 1
Max_cs = 1
')
Do
Max_cs = 0
Spiout Read_address_1 , 1
Spiin Rtd_h , 1
Spiin Rtd_l , 1
Max_cs = 1

Shift Rtd , Right , 1 ' 16bit -> 15Bit


Temperatur = Rtd / 16 ' Temperature calculation
Temperatur = Temperatur - 256
Locate 1 , 8
Lcd " "
Locate 2 , 8
Lcd " "
Locate 3 , 8
Lcd " "
Locate 4 , 6
Lcd " "
Locate 1 , 1
Lcd "RTD_h: " ; Rtd_h
Locate 2 , 1
Lcd "RTD_l: " ; Rtd_l
Locate 3 , 1
Lcd "RTD : " ; Rtd
Locate 4 , 1
Lcd "Temp: " ; Temperatur

Waitms 500
Loop[code]

Greetings
Murmel
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Sun Feb 04, 2024 3:30 pm    Post subject: Reply with quote

Please take a one step back.
If you have proper SPI config then try it first.
Set address to Config_write &H80 and write it with config value.
Then set address to Config_read &H00 and read this config back.
Then LCD it and values should match.

Code:
Locate 1 , 1 : Lcd Bin(Max_31865_config_register)
Locate 2 , 1 : Lcd Bin(Readed_config)

_________________
Check B-Flash -my MCS bootloader app for Android
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum